Hello guys I am new to Ruby . I am try to create form with form builder What is difference between
<%=form_for @post %>
and
<%=form_for :post %>
Hello guys I am new to Ruby . I am try to create form with form builder What is difference between
<%=form_for @post %>
and
<%=form_for :post %>
form_for
creates an instance of the form builder object:
A FormBuilder object is associated with a particular model object and allows you to generate fields associated with the model object. The FormBuilder object is yielded when using form_for or fields_for
@post
is an instance variable. :post
isn't
This means that when you load a <%= form_for @post %>
, you're populating the form builder object with data from the instance (allowing Rails to maintain the data when you have errors etc)
If you're unsure about @instance_variables
in Ruby, you might want to check out the Ruby On Rails beginners' guide
if you are use symbol :post like
<%=form_for :post %>
then it create
<form action="/posts" method="post">
if you are use instance @post like
<%=form_for @post %>
then it create
<form action="/posts/create" class="class_name" id="id_name" method="post">