Search code examples
ruby-on-railsdecent-exposure

How to break down decent-exposure code to classic Rails way?


Can anyone break this code down for me and explain how this can be done in classic Rails way with callbacks(if any) and methods?

class SearchController < ApplicationController
  expose :search_result, -> { SearchService.new(search_params).call }

  def search_params
    params.permit(:q, :scope)
  end
end

Solution

  • class SearchController < ApplicationController
      def index
        @search_result = SearchService.new(search_params).call
      end
    
      def search_params
        params.permit(:q, :scope)
      end
    end
    

    expose :search_result, -> { SearchService.new(search_params).call } creates a variable @search_result