I have a model, and I have a view that displays a form for creating a new object based on that model. Let's call that form, Form1
.
Once the user submits Form1
, the object is created. I then want to display, on the following page, a second form Form2
, which asks the user to check off various options before the object is saved to the database.
My problem is probably extremely basic. I don't know how to create Form2
, given that it is not tied directly to the model. Because I am a Rails
newbie, I have only created forms as following:
form_for(@object) { |f| ... }
@object
is an object instantiated from the model
Problem: I do not believe that kind of code will work for my purposes here. How do I create Form2
, given that it must not be based on @object
or @object
's model?
Some specifics from my app:
The site accepts values (Form1
) before redirecting to an OAuth
server.
When the user verifies her credentials on the OAuth
server, she is redirected back to my site. An XML-RPC
request then retrieves information about the user's account on the OAuth
server.
The XML
response may indicate that the user has only one account on the OAuth
server. If so, some values are retrieved from the XML
and added to the object--which is then (finally) saved in the database--and the user is redirected to a success page.
However, if the XML
response indicates that the user has multiple accounts on the OAuth
server, I want to display a form (Form2
) that allows the user to select which accounts on the OAuth server to associate with my site. So Form2
really asks the user how many objects to create, rather than about specific attributes of an object.
Use form_tag
instead of form_for
, then use the appropriate form helpers: text_field_tag
instead of f.text_field
, text_area_tag
instead of f.text_area
, etc. Example:
<%= form_tag "/my_controller/update2" do %>
<%= text_field_tag "account", "default info" %>
<%= submit_tag "Save" %>
<% end %>
The Rails API site has a great reference to all of the _tag helpers: http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html