Forum: Ruby on Rails Easy question: need clarification of the form_for idiom

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Douglass Turner (Guest)
on 2006-06-14 00:01
I've been trying wrap my head around one specific section of Recipe 57
in "Rails Recipes". The recipe is for image upload and processing.


Iâ??m staring at:

<% form_for   :image,   @image, :url => {:action => â??createâ?? }, :html =>
{multipart => true } do | f | %>
â?¦
<% end %>

and the associated controller method â??createâ??:

def create
 @image = Image.create  params[ :image ]
end

Can someone please clarify for me what role :image and @image in both
the form and the method play?

Does :image correspond to the ID of the instance of the Image object
created in the calling controller?

It appears both :image and @image are unused in the form, what up?

Within the create method, is :image the ID of an image in the dbase?
Where was it set?

I would really appreciate clarification of this.

Thanks,
Doug
lisa-u (Guest)
on 2006-06-14 03:18
Hi.  I'm a newbie myself, but I've had the same question. the form_for
tag was not used in the page that I was looking at (
http://manuals.rubyonrails.com/read/chapter/57 ).  It was form_tag,
which explains why you didn't see :image or @image.
In that example, the form returns a hash of the info you posted.  The
"name" attribute in the input specifies the field that you want to
satisfy.  It's more apparant what you want to do if you use the helper
function
<%= file_field(:model, 'image') %>
This is replaced by html tags.

I'm still learning so I don't know a whole lot, but this might help a
bit (I know it helped me)
Four Days On Rails:  http://rails.homelinux.org/
and of course the docs.
Here is my own post that I asked about accessing fields in the form:
http://www.ruby-forum.com/topic/68373#87558


Douglass Turner wrote:
> I've been trying wrap my head around one specific section of Recipe 57
> in "Rails Recipes". The recipe is for image upload and processing.
>
>
> Iâ??m staring at:
>
> <% form_for   :image,   @image, :url => {:action => â??createâ?? }, :html =>
> {multipart => true } do | f | %>
> â?¦
> <% end %>
>
> and the associated controller method â??createâ??:
>
> def create
>  @image = Image.create  params[ :image ]
> end
>
> Can someone please clarify for me what role :image and @image in both
> the form and the method play?
>
> Does :image correspond to the ID of the instance of the Image object
> created in the calling controller?
>
> It appears both :image and @image are unused in the form, what up?
>
> Within the create method, is :image the ID of an image in the dbase?
> Where was it set?
>
> I would really appreciate clarification of this.
>
> Thanks,
> Doug
This topic is locked and can not be replied to.