Reputation: 11
I'm new in Ruby on Rails and I'm wondering on how to instantiate my form action on every page (instead of putting the method on every action)?
In this case I put contact form on the footer.
Upvotes: 1
Views: 306
Reputation: 16331
If you want to add contact data to the footer, why not add it to the application layout? This is rendered for every single view. Anything below the "yield" will effectively be in the footer.
If there is actual programmatic stuff that needs to happen, you can use the application controller as well. Add a before_action
, for example, to populate your variables so that they can be accessed in the view.
In your case I could imagine a call like this:
@footer_contact = Contact.new
in your application controller in a before filter. Then, in the application layout:
<%= form_for @footer_contact do |f| %>
Upvotes: 2