Geo
Geo

Reputation: 96827

How can I create a form in Rails without having to use form_for and a model instance?

First of all, I'm a Rails newbie. I can hold my own in Ruby, but Rails is a whole different story for me. I like the development speed Rails offers me, but I can't seem to make peace with the existing documentation.

For all of my forms so far, I used form_for, with an instance for the model I needed to create ( for example, submitting a new book ). I would really like to be able to just write something like :


<% form(:action => "whatever") %>
  <% text_field ... %>
  <% file_field ... %>
<% end %>

From the articles I read online, I understood that this was the way things got done in Rails < 2.0 . Is there anyway of doing this in Rails > 2.0, or something equivalent to it ? Can you please post a snippet ?

Upvotes: 18

Views: 9707

Answers (1)

Jim Puls
Jim Puls

Reputation: 81082

Take a look at form_tag.

<% form_tag '/posts' do %>
  <div><%= submit_tag 'Save' %></div>
<% end %>

Upvotes: 23

Related Questions