0

谁能帮我分解这段代码并解释如何以经典的 Rails 方式使用回调(如果有)和方法来完成?

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

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

1 回答 1

0
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 }创建一个变量@search_result

于 2020-05-30T10:26:18.920 回答