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
How many types of variables are available in ruby class?
Explain rvm in rails?
How will be the future for ruby on rails?
what are benefits of using active record as opposed to raw sql queries?
Name some rails ide or editor.
what are some advantages of using ruby on rails?
Who designed active record in rails?
What does session and cookies represent in ruby on rails?
What is rails migration? What can it do?
what are the limits of Ruby on Rails?
how you can run Rails application without creating databases?
What is the symbol garbage collector?
what is Rails Migration?
who developed rails?
What are the various components of rail?