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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Chad wrote:> 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Apr 11, 3:07 pm, Jon Garvin <jgarvin.li...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Chad wrote: > > 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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! Chad wrote:> 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 Apr 11, 3:07 pm, Jon Garvin <jgarvin.li...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Chad wrote: >> >>> 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. >> > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Apr 11, 5:34 pm, Jon Garvin <jgarvin.li...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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! > > Chad wrote: > > 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 Apr 11, 3:07 pm, Jon Garvin <jgarvin.li...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> Chad wrote: > > >>> 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. Chad wrote:> 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 Apr 11, 5:34 pm, Jon Garvin <jgarvin.li...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> 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! >> >> Chad wrote: >> >>> 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 Apr 11, 3:07 pm, Jon Garvin <jgarvin.li...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> Chad wrote: >>>> >>>>> 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. >>>> > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---