Shimon Shtein wrote:
ScopesPerAction concern is needed if you want to add the ability to customize actions in your controller.
This looks more of refactoring step.
If you want to customize the scope for existing controller (HostsController is the only one that uses ScopesPerAction right now), you will need to register your scope filter in the plugin declaration:
[...]
So if we take an example from foreman_discovery plugin.
https://github.com/theforeman/foreman_discovery/blob/develop/app/controllers/discovered_hosts_controller.rb#L20-L25
The `includes` method chained in DiscoveredHostsController#index would be removed and instead the plugin scope will come into play ?
## The index action would look like:
def index
@hosts = resource_base.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
fact_array = @hosts.collect do |host|
[host.id, Hash[host.fact_values.joins(:fact_name).where('fact_names.name' => Setting::Discovered.discovery_fact_column_array).pluck(:name, :value)]]
end
@host_facts = Hash[fact_array]
end
## Some initializer:
Foreman::Plugin.register :my_plugin do
add_controller_action_scope(DiscoveredHostsController, :index) { |base_scope|
base_scope.includes([
:location,
:organization,
:model,
:discovery_attribute_set
], {:interfaces => :subnet}) }
end
I don't think that's what it's meant for. Using `ScopesPerAction` sounds legitimate wrt foreman_discovery.