Rails: How do I pass a global variable from routes to controllers and helpers? -


i have rails app handles 2 domains. app set described in this blogpost. based on base url visited, routes.rb determines controller , action should triggered.

the 2 domains share lot of files, e.g. layouts/application.html.haml, layouts/footer.html.haml, etc. in layouts/application.html.haml need reference different navigation files. write:

= render "layouts/navigation" 

but multiple domains wish write like:

= render "layouts/#{domain_constraint}/navigation" 

... domain_constraint here depending on domain constraint matched in routes.

so how pass on constraint routes, later on access constraint in helpers/application_helper.rb method , controllers/application_controller.rb method?

in blog post referenced... looks request.domain should available within controllers , views. meaning should able key off of value of request.domain request header rendering layout.

= render "layouts/#{request.domain}/navigation" 

then, suggest make helper methods in applicationcontroller , mark them helper_method well.

applicationcontroller < actioncontroller::base   helper_method :my_method    def my_method     # ... whatever , access `request.domain` again if want   end end 

methods marked helper method in way available controllers , views, alike.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -