Aditia Lukman Ernawan
Aditia Lukman Ernawan

Reputation: 11

Rails form on footer, how to instantiate footer variable on every pages/actions?

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

Answers (1)

David Hoelzer
David Hoelzer

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

Related Questions