Skip to main content

Posts

Featured Post

Define a Procfile

Recent posts

credentials not working in staging/production | Ruby On Rails

  Create credentials for production environment To create credentials for  production  environment, we can run the following command: $ EDITOR="code --wait" rails credentials:edit --environment production The above command does the following: Creates  config/credentials/production.key  if missing. Don’t commit this file. Creates  config/credentials/production.yml.enc  if missing. Decrypts and opens the production credentials file in the default editor. We share the  production.key  with limited members of our team who have access for production deployment.

upload attachment via base64 | Active Storage | Ruby On Rails

models/attachment.rb class Attachment < ApplicationRecord attr_accessor :base64 has_one_attached :file after_initialize :set_file private def set_file return if self . base64 . blank? decoded_data = Base64 . decode64 ( self . base64 . split ( ',' )[ 1 ]) self . file = { io: StringIO . new ( decoded_data ), content_type: 'image/jpeg' , filename: 'image.jpg' } end # end of private end

only large files upload on S3 | Ruby On Rails

models/attachment.rb class Attachment < ApplicationRecord after_initialize :set_storage private def set_storage # larger that 5mb file would be upload on s3 if file . blob . byte_size > 5_000_000 Rails . application . config . active_storage . service = :amazon else Rails . application . config . active_storage . service = :local end end # end of private end

rspecs for devise-token-auth | Ruby On Rails

sessions_controller_spec.rb require 'rails_helper' RSpec . describe DeviseTokenAuth :: SessionsController , type: :controller do before do @request . env [ "devise.mapping" ] = Devise . mappings [ :user ] end describe "POST #create" do context "when input invalid credentials" do it "should not login" do post :create , params: { email: 'invalid_user@yopmail.com' , password: 'invalid_password' } expect ( response . status ). to eq ( 401 ) expect ( subject . current_user ). to be_nil end end context "when input valid credentials" do let ( :valid_email ) { 'valid_user@yopmail.com' } let ( :valid_password ) { 'password' } let! ( :user ) { create ( :user , :with_role , email: valid_email , password: valid_password , role_name: 'aba_admin' ) } it "should logi

Swagger File | Devise Token Auth

openapi : 3.0.1 info : title : API consumes : - application/json produces : - application/json servers : - url : http://localhost:3000 schemes : - "https" - "http" paths : "/auth" : post : summary : User registration requestBody : content : application/json : schema : $ref : "#/definitions/UserRegistrationParameters" responses : "200" : description : "Valid input" content : application/json : example : status : 'success' data : email : "testuser2@yopmail.com" uid : "testuser2@yopmail.com" first_name : "testuser2" last_name : "lname" role : "ABA Admin" "422" : description : "Invalid input"

Promises and Async-await in depth : Asynchronous Programming in Javascript

Promises and Asynchronous Programming One of the most powerful aspects of JavaScript is how easily it handles asynchronous programming. As a language created for the Web, JavaScript needed to be able to respond to asynchronous user interactions such as clicks and key presses from the beginning. Node.js further popularized asynchronous programming in JavaScript by using callbacks as an alternative to events. As more and more programs started using asynchronous programming, events and callbacks were no longer powerful enough to support everything developers wanted to do.  Promises  are the solution to this problem. Promises are another option for asynchronous programming, and they work like futures and deferreds do in other languages. A promise specifies some code to be executed later (as with events and callbacks) and also explicitly indicates whether the code succeeded or failed at its job. You can chain promises together based on success or failure in ways that make your code easier t