I am using acts_as_attachment to upload multiple files and it works great. My problem is when I go to display the files and images. If one or more files are missing I get an error stating "can't convert nil into String" what I then tried is the following: <% if "".blank? %> <div id="pdf" style="display:none;"></div> <% else %> <div id="pdf"><%= link_to image_tag('/images/common/reader_icon.jpg'), @report.public_filename %></div> <% end %> This clears the error but then it also hides the pdf icon for all other records. How would I go about hiding the pdf icon if there isn't a file associated with that record but show it if there is a file? Hope this makes sense and thanks for any help.
on 2007-04-11 22:54
on 2007-04-11 23:07
Chad wrote: > <% end %> > What are you trying to do here... <% if "".blank? %> That will always evaluate to 'true'. I suspect what you really want is something more like.. <% if @report.missing? %> and implement you're own 'missing?' method to test if the file is available or not.
on 2007-04-11 23:31
I am fairly new to Rails and am not 100% sure if I understand what you mean. Could you please explain further or provide and example. thanks,
on 2007-04-12 01:36
That's not really Rails as much as Ruby. In your if statement, you're condition is checking if an empty string is blank, which it will always be. You'd get the exact same result if it said <% if 1 == 1 %>, or even <% if true %>. The condition you need to be checking is whether or not the file in question is available on the server. If you're new to programming, I'd highly recommend starting with this book, http://www.pragmaticprogrammer.com/titles/fr_ltp/ or if you've programmed in other languages before, but just aren't grasping the OO Syntax of Ruby, then this would be better. http://www.pragmaticprogrammer.com/titles/ruby/index.html Good luck!
on 2007-04-12 04:12
So if I understand you what I would need to do is something along the lines of this? <% if file_is_in_database %> <div id="pdf"><%= link_to image_tag('/images/common/reader_icon.jpg'), @report.public_filename %></div> <% else %> <div id="pdf" style="display:none;"></div> <% end %> If this is what I need to do, then how do I go about verifying that the file is in the database? I am currently reading the Pickaxe book trying to grasp Ruby. Thanks.
on 2007-04-12 17:11
Yup, that's right. I'm not familiar with acts_as_attachment, but I would bet it's got a method to check for the existance of said file.