Some .erb / herlper.rb nuance I am missing??

this is my view:

        <td align="left">         <% setupsheets_missing = true             @series800.setupsheets.each do |sheet|               setupsheets_missing = false               %>               <%= link_to( image_tag(sheet.public_filename(:small), :border=>1, :style=>"margin- right: 3p"),                 'show_setup_sheet',:popup => ['sheet window', 'height=780,width=620']) %>               <%             end             if setupsheets_missing               %>               <%=               image_tag("/setupsheets/ missing_small.gif", :border=>1, :style=>"margin-right: 3px")%>               <%             end %>         </td><td></td><td></td></tr>

It works, but it is damned ugly. if attachment_fu has saved multiple files, I get a list of thumb picture links if it has only saved on I get one thumb picture link if it hasn't any I get a image_tag to a thumb bearing the word "missing"

I would like to replace the abomination in the view code above with:

<td align="left"><%= sheet_links_for(@series800,:small) % ></td>

and a helper routine:

  def sheet_links_for(series800,size = :small)     sheets_present = false     series800.setupsheets.each do |sheet|       sheets_present = true

link_to( image_tag(sheet.public_filename(size), :border=>1,:style=>"margin- right: 3px"),         'show_setup_sheet',:popup => ['sheet window', 'height=780,width=620'])     end     unless sheets_present        image_tag("/setupsheets/ missing_small.gif", :border=>1,:style=>"margin-right: 3px")     end   end

But no... the 'missing tag' does show up, but the two links are nowhere to be found.

I have been trying to spot the error for the past week... been over this with a fine tooth comb, substituting image tags for the 2 links.

any ideas? also is there a clean way to test for sheets present without introducing a local variable.

Thanks in advance.

But no... the 'missing tag' does show up, but the two links are nowhere to be found.

You need to return from the helper the entirety of what you want rendered. However the return value of your function is either the missing tag image, or (if sheets_present is true) then just nil. In the original form this was handled by you using <%= in various points, but with a helper like this you'll have to handle this yourself eg output = "" output << link_to(...) ... and then return output from your function

also is there a clean way to test for sheets present without introducing a local variable.

if series800.setupsheets.any?   ... else   image_tag("/setupsheets/ missing_small.gif", :border=>1,:style=>"margin-right: 3px") end

Fred

Fred,   I did not understand the helper transfer mechanism...   Thank you! :slight_smile: (jubilation, joy, and much happiness :slight_smile: :slight_smile:

Steven