form_for and form_tag

form_for and form_tag both are used to submit the form in ruby on rails.
but the way of handling objects related to model is different.

form_for:

you should use form_for for a specific model i.e while crating an new row in database. form_for will perform the standard http post which is having fields related to active record objects.

here is the example for using form_for in ruby on rails:

{ :action => “update” } do |f| %>

then in here you can use the f object to create input field.

First name: <%= f.text_field :firstname %>
Last name : <%= f.text_field :lastname %>
Biography : <%= f.text_area :biography %>

<% end %>

form_tag:

form_tag just creates an form as an normal form. form_for will perform the standard http post without any model backed and has normal fields. this is used mainly when specific things need to be submitted via form

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s