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

**URL:** <https://www.ruby-forum.com/t/some-erb-herlper-rb-nuance-i-am-missing/149652>\
**Category:** Rails\
**Created:** [September 27, 2008, 11:17am UTC](https://www.ruby-forum.com/t/some-erb-herlper-rb-nuance-i-am-missing/149652 "2008-09-27T11:17:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ee\_smajors](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a698b9/32.png) [@ee\_smajors](https://www.ruby-forum.com/u/ee_smajors)\
**Post date:** [September 27, 2008, 11:17am UTC](https://www.ruby-forum.com/t/some-erb-herlper-rb-nuance-i-am-missing/149652/1 "2008-09-27T11:17:39Z")

</div>

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 %\>

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:

\<%= sheet\_links\_for(@series800,:small) % \>

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.

---

<div class="post-metadata">

**Author:** ![ee\_smajors](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a698b9/32.png) [@ee\_smajors](https://www.ruby-forum.com/u/ee_smajors)\
**Post date:** [September 27, 2008, 11:23am UTC](https://www.ruby-forum.com/t/some-erb-herlper-rb-nuance-i-am-missing/149652/2 "2008-09-27T11:23:29Z")

</div>

On Sep 27, 2:01 am, ee\_smajors [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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

---

<div class="post-metadata">

**Author:** ![ee\_smajors](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a698b9/32.png) [@ee\_smajors](https://www.ruby-forum.com/u/ee_smajors)\
**Post date:** [September 28, 2008, 12:20am UTC](https://www.ruby-forum.com/t/some-erb-herlper-rb-nuance-i-am-missing/149652/3 "2008-09-28T00:20:13Z")

</div>

Fred,  
I did not understand the helper transfer mechanism…  
Thank you! 🙂 (jubilation, joy, and much happiness 🙂 🙂

Steven

On Sep 27, 1:22 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
