Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

difference between form_for and form_tag

Answer Posted / arpita patel

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:

<% form_for :user, @user, :url => { :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


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

<% form_tag '/posts' do -%>
<%= text_field_tag "post", "firstname" %>
<% end -%>

Is This Answer Correct ?    54 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is the purpose of the resources method in the code snippet below?

872


If you want to set up a one-to-one relationship between two models, you'll need to add belongs_to to one, and has_one to the other. How do you know which is which?

835


Explain the controller in rails?

911


What are float, dig and max?

1015


how can you declare a block in Ruby?

947


Why ruby on rails is used for?

872


Explain Get and post method?

925


What is the purpose of require_relative in ruby?

869


What is cross-site request forgery (csrf)? How is rails protected against it?

997


How many types of variables are available in ruby class?

880


How are observers and callbacks different from each other?

781


what is different between activerecord::relation's count, length and size methods?

900


what are helpers and how to use helpers in ror?

885


Explain me what is the function of orm in ruby on rails?

772


Explain me what is the difference between concern and application_controller.rb in ruby on rails?

801