如何将体面的曝光代码分解为经典 Rails 方式?
How to break down decent-exposure code to classic Rails way?
任何人都可以为我分解这段代码并解释如何以经典的 Rails 方式使用回调(如果有)和方法来完成吗?
class SearchController < ApplicationController
expose :search_result, -> { SearchService.new(search_params).call }
def search_params
params.permit(:q, :scope)
end
end
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
任何人都可以为我分解这段代码并解释如何以经典的 Rails 方式使用回调(如果有)和方法来完成吗?
class SearchController < ApplicationController
expose :search_result, -> { SearchService.new(search_params).call }
def search_params
params.permit(:q, :scope)
end
end
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