views:

86

answers:

1

I implemented a restfull controller with all the correct actions and views. It works currently perfectly with a new_html.erb view that uses a form_for containing a structure like:

<% form_for @ecard do |f| %>

when watching some tutorials i saw that people also use the structure:

<% form_for :ecard do |f| %>

It sounds logical.. but when i try to use the <% form_for :ecard do |f| %> the resulting post goes to a different action then using <% form_for @ecard do |f| %>..

<% form_for @ecard do |f| %> -> html result is:

<form action="/ecards" class="new_ecard" id="new_ecard" method="post">

<% form_for :ecard do |f| %> -> html result is:

<form action="/ecards/new" method="post">

So i am wondering what i am missing, the difference in using :ecard and @ecard are obvious when i look at the generated html but i am still wondering what the reasoning behind this is!

So can anyone please explain what the difference is and what structure i am supposed to be using?? Is it <% form_for @ecard do |f| %> or <% form_for @ecard do |f| %>

+2  A: 

Marco,

This has been answered on the site before:

http://stackoverflow.com/questions/957204/instance-variable-vs-symbol-in-ruby-on-rails-formfor

I hope that clears it up.

Carlos
I looked at the link but still can not figure out what the good / best way is. I think i will have to read the stuff a few times more to understand it.
Marco
Marco, the short answer is, if you're using RESTful resources, you use the instance variable method.Take a look at the following documents for more information:http://apidock.com/rails/ActionView/Helpers/FormHelper/form_for
Carlos