add search in rails by simple rails api

  

1. add route -----------------------------

 namespace :bx_block_fee do

    resources :fees, :only => [:index, :create, :update, :show, :destroy] do

        post 'import', on: :collection

        get 'export', on: :collection

        get 'search_fee', on: :collection

        get 'search', on: :collection 

    end


2. add method in controller  -----------------------------

   def search

      fees = Fee.where('name ILIKE ?', "%#{params[:name]}%").paginate(page: params[:page], per_page: 20)

      if fees.present?

        render json: FeeSerializer.new(fees, meta: { total_pages: roles.total_pages, message: 'Fee search list' }).serializable_hash,

               status: :ok

      else

        render json: { message: 'No records.' }, status: :not_found

      end

    end


3. check with postman  with url   -----------------------------

method - GET
url - localhost:3001/bx_block_fee/fees/search




Comments

Popular posts from this blog

Rails 7 Features :: Comparison with Rails 6 and Rails 5