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 ?
1.3 Helpers for Generating Form Elements Rails provides a series of helpers for generating form elements such as checkboxes, text fields, and radio buttons. These basic helpers, with names ending in _tag (such as text_field_tag and check_box_tag ), generate just a single <input> element.
form_with syntax. form_with is a Rails form helper, similar to form_tag and form_for which have both been soft deprecated. It is a form helper that allows us to use ruby code to build an HTML form. form_with can bind a form to a model object or it can create a simple form that does not require a model.
Take a look at form_tag
.
<% form_tag '/posts' do %>
<div><%= submit_tag 'Save' %></div>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With