difference between form_for and form_tag
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / saravanan
The difference between the two is that form_tag just outputs
a <form>tag , It doesn't relies on activerecord object
and form_for gives you a means of accessing some wrapped object.
Is This Answer Correct ? | 9 Yes | 7 No |
Tell me what is orm (object-relationship-model) in rails?
What is ruby on rails & why it is used for?
how you can list all routes for an application?
What is a ruby singleton method ?
what is Ruby on Rails?
What are the three methods to install ruby on rails?
Do you know the role of garbage collection in ruby on rails?
Do you know what is rake in rails?
Can you explain me how rails implements ajax?
Do you know what are the types of caching used in rails, what are they?
What is the function of orm in ruby on rails?
What is a webrick web server?