views:

885

answers:

1

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 ?

+6  A: 

Take a look at form_tag.

<% form_tag '/posts' do -%>
  <div><%= submit_tag 'Save' %></div>
<% end -%>
Jim Puls
+1, FormTagHelper is the generic version of FormHelper. The latter has form_for and is specific to AR models, while the former has form_tag and can be used for anything.
Sarah Mei
Thank you! I was hoping to find something like this!
Geo
Please tell me, if it's not too much to ask, how do I limit a text_field's size using it?If I add a text_field "some_name",:size => 50 , the HTML generated is wrong.
Geo
text_field_tag to the rescue!
Geo