Douglass Turner
2006-Jun-13 22:01 UTC
[Rails] Easy question: need clarification of the form_for idiom
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 -- Posted via http://www.ruby-forum.com/.
lisa-u
2006-Jun-14 01:18 UTC
[Rails] Re: Easy question: need clarification of the form_for idiom
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-- Posted via http://www.ruby-forum.com/.