Reputation: 2235
In my Rails 4 app I have the following route:
scope ':section' do
resources :articles
resources :features
resources :galleries
end
The section is set in the application controller:
@current_section = params[:section]
In my views, I am linking to pages using articles(@channel), article_path(@channel, article). It works but I have the feeling it could be DRYer. Is there a way that, once set, :section becomes implicit for all path helpers?
Upvotes: 0
Views: 71
Reputation: 6724
Have you tried
def default_url_options
{ section: @current_section }
end
in ApplicationController
?
cf. http://edgeguides.rubyonrails.org/action_controller_overview.html#default-url-options
Upvotes: 1