I’m trying to create a very simple email signup form, where the user can just enter their email and press submit.
I’d like the signup form to be a partial, so I can use it anywhere on the site.
Forms are coded like this:
<%= form_for @subscription do |f| %>
How to do tell the form that @subscription is a Subscription.new if, say, the current view, controller, and action is the home page?
Thanks!
As an option you can do:
One thing though, I haven’t tried this myself. Try it and see if it works.
Edit:
Sorry, I didn’t get the question in the first read.
You can set the
@subscriptioninstance variable toSubscription.newin the home controller, and then, pass it to the partial (inside the main view) like this:Hope this helps.