Alien8 Recordings
2006-Jan-25 04:35 UTC
[Rails] url_for_file_column in parent model''s view
Hi All, I am using the file_column plugin to upload images. The model that I am using is simply called images (id, name, caption - name being the "file" column) and it belongs_to a parent model called books which has_many images. I was able to figure out how to enter the images into the correct model when updating of form of the parent model (books). Now I need to figure out how to view the images in simple display view of the parent model (books). I am not sure about the syntax of the url_for_file_column helper. Here is what I have so far: <% for image in @book.images %> <label for="image_name">Image:</label> <div class="reviewfield"><% url_for_file_column image, image.name, "thumb" %> </div><br /> <label for="image_caption">Caption</label> <div class="reviewfield"><%= image.caption %></div><br /> <% end %> Which produces the following error: You have a nil object when you didn''t expect it! The error occured while evaluating nil.image.name_relative_path I also have a more general question about this function. How could url_for_file_column figure out which model object (record) to display if we are only to pass it the names of the model and relevant attribute? Shouldn''t we have to pass it an ID as well? Thanks, Sean
Alien8 Recordings
2006-Jan-25 06:19 UTC
[Rails] url_for_file_column in parent model''s view
Hi All, I actually was able to get this to work after doing some more searching. In case anyone else stumbles up this, there were two problems with my code. First I used <% instead of <%= so nothing was being output. Second, when iterating over an array you have to use <% = image_tag url_for_file_column "image", "name", "thumb" %> instead of just <%= url_for_file_column "image", "name", "thumb" %> Sorry for the noise. Sean On 24-Jan-06, at 11:34 PM, Alien8 Recordings wrote:> Hi All, > > I am using the file_column plugin to upload images. The model that > I am using is simply called images (id, name, caption - name being > the "file" column) and it belongs_to a parent model called books > which has_many images. I was able to figure out how to enter the > images into the correct model when updating of form of the parent > model (books). Now I need to figure out how to view the images in > simple display view of the parent model (books). > > I am not sure about the syntax of the url_for_file_column helper. > Here is what I have so far: > > <% for image in @book.images %> > <label for="image_name">Image:</label> > <div class="reviewfield"><% url_for_file_column image, image.name, > "thumb" %> </div><br /> > > <label for="image_caption">Caption</label> > <div class="reviewfield"><%= image.caption %></div><br /> > > <% end %> > > Which produces the following error: > You have a nil object when you didn''t expect it! > The error occured while evaluating nil.image.name_relative_path > > I also have a more general question about this function. How could > url_for_file_column figure out which model object (record) to > display if we are only to pass it the names of the model and > relevant attribute? Shouldn''t we have to pass it an ID as well? > > Thanks, > Sean > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >______________ ALIEN8 RECORDINGS P.O. BOX 666, STATION R MONTREAL, QC CANADA, H2S 3L1 http://www.alien8recordings.com