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?
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.
>
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.
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,
or if you’ve programmed in other languages before, but just aren’t
grasping the OO Syntax of Ruby, then this would be better.
Good luck!
Chad wrote: