I’m adding a site-wide form for asking questions on a rails site. The models/views/controllers for the resource question are already created. Going to question/new shows the form as you’d expect. Now I want to display a site-wide question form (the only difference with this one is that it only shows mandatory fields). Question: should I create a new question object in application_controller and pass that to the rails form_for helper, or should I create a new _form2 partial(in the question view) and just include that in my site-wide template?
Thank you.
Create a
question_formpartial in theviews/sharedfolder, and reference that from the site wide template.Edit: in reply to where to get the @question variable from
You have two options in my mind, you can load the variable in ApplicationController:
(You should be careful of conflicts with the @question variable in this case)
Or probably better, you can create a method in ApplicationHelper:
Then in your view, instead of referencing the partial, you reference the helper:
In this case you would need to reference the variable in the partial as a local variable, so
questioninstead of@question.Hope that helps.