# Trouble with if statement in helper function

**URL:** <https://www.ruby-forum.com/t/trouble-with-if-statement-in-helper-function/139859>\
**Category:** Rails\
**Created:** [June 8, 2008, 8:40am UTC](https://www.ruby-forum.com/t/trouble-with-if-statement-in-helper-function/139859 "2008-06-08T08:40:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![skirkpatrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@skirkpatrick](https://www.ruby-forum.com/u/skirkpatrick)\
**Post date:** [June 8, 2008, 8:40am UTC](https://www.ruby-forum.com/t/trouble-with-if-statement-in-helper-function/139859/1 "2008-06-08T08:40:57Z")

</div>

I have a helper function that returns a bunch of html but i’m having  
trouble with this if statement

```
  ret += current_id.to_s + '<br>'
  ret += root_id.to_s

  if current_id == root_id then
    ret += 'Total Time: ' + total_time.to_s + ' minute(s)<br>'
  end

```

the values for current\_id and root\_id are valid and i can see them  
output to the screen but for some reason i’m getting the error:

can’t convert nil into String

am i using incorrect syntax here?

if i remove the if statement the code works fine.

thanks in advance!!

---

<div class="post-metadata">

**Author:** ![skirkpatrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@skirkpatrick](https://www.ruby-forum.com/u/skirkpatrick)\
**Post date:** [June 8, 2008, 2:52pm UTC](https://www.ruby-forum.com/t/trouble-with-if-statement-in-helper-function/139859/2 "2008-06-08T14:52:30Z")

</div>

Is total\_time valid too?  
It’s the only thing that gets converted to string within the if  
statement…

---

<div class="post-metadata">

**Author:** ![skirkpatrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@skirkpatrick](https://www.ruby-forum.com/u/skirkpatrick)\
**Post date:** [June 8, 2008, 2:57pm UTC](https://www.ruby-forum.com/t/trouble-with-if-statement-in-helper-function/139859/3 "2008-06-08T14:57:21Z")

</div>

Thorsten M. wrote:

> Is total\_time valid too?  
> It’s the only thing that gets converted to string within the if  
> statement…

yea, if i comment out the if and end statement the program works fine,  
but it prints total time every time:

```
  ret += current_id.to_s + '<br>'
  ret += root_id.to_s

  # if current_id == root_id
    ret += 'Total Time: ' + total_time.to_s + ' minute(s)<br>'
  # end
```

---

<div class="post-metadata">

**Author:** ![skirkpatrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@skirkpatrick](https://www.ruby-forum.com/u/skirkpatrick)\
**Post date:** [June 8, 2008, 3:07pm UTC](https://www.ruby-forum.com/t/trouble-with-if-statement-in-helper-function/139859/4 "2008-06-08T15:07:14Z")

</div>

You didn’t post all your code or the error message, so I can only  
guess…  
The if statement looks ok  
since the assigned var is name ret, I guess that’s what your helper  
returns

Do you have an explicit if statement at end of the method?  
Or does more code come?

Otherwise:  
If the if statement fails for current\_id != root\_it,  
your method may return nil (result of if)  
and the following code may interpret that and fail using it as string

---

<div class="post-metadata">

**Author:** ![skirkpatrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@skirkpatrick](https://www.ruby-forum.com/u/skirkpatrick)\
**Post date:** [June 8, 2008, 3:42pm UTC](https://www.ruby-forum.com/t/trouble-with-if-statement-in-helper-function/139859/5 "2008-06-08T15:42:34Z")

</div>

yes, that’s obvious.  
The last lines are the if statement. (As long as it fails). This will  
return nil and then the recursive call in line 55 fails. (Otherwise it  
returns ret and is ok)

Since it’s not sure, that ret contains anything at all, something like  
that should work:

ret ||= “”

as last line. If ret contains something, that’ll be returned, if not  
it’ll return an empty string.  
This would make sure, that the method returns a string in any case.

---

<div class="post-metadata">

**Author:** ![skirkpatrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@skirkpatrick](https://www.ruby-forum.com/u/skirkpatrick)\
**Post date:** [June 8, 2008, 3:22pm UTC](https://www.ruby-forum.com/t/trouble-with-if-statement-in-helper-function/139859/6 "2008-06-08T15:22:10Z")

</div>

Thorsten M. wrote:

> You didn’t post all your code or the error message, so I can only  
> guess…  
> The if statement looks ok  
> since the assigned var is name ret, I guess that’s what your helper  
> returns
> 
> Do you have an explicit if statement at end of the method?  
> Or does more code come?
> 
> Otherwise:  
> If the if statement fails for current\_id != root\_it,  
> your method may return nil (result of if)  
> and the following code may interpret that and fail using it as string

yea i wonder if it it is trying to put the result from the if statement  
as part of the return value.

i’ll post the rest of the helper function but i’ll warn you it’s not  
pretty…it does work though…suprisingly.

here is a link to the page so you can see what it does without the if  
statement if you are interested:  
[http://wl-dev.kuliksco.com/manufactures/247](http://wl-dev.kuliksco.com/manufactures/247)

from my view i am calling:

\<%= tree\_ul(@manufacture, 1, 1, @manufacture.make\_time,  
@manufacture.id.to\_i, @manufacture.id.to\_i) %\>

and in my helper here is the code:

def tree\_ul(manufacture, total\_num, make\_num, total\_time, root\_id,  
current\_id)

```
if manufacture.manufacture_materials.length > 0
  ret = '<ul>'

  manufacture.manufacture_materials.each do |manufacture_material|

  # Get manufacture for material
  manufacture = 

```

Manufacture.find\_by\_item\_id(manufacture\_material.item\_id)

```
  if manufacture.blank?
    # Material does not have manufacture

    total_num = total_num * manufacture_material.required_num.to_f / 

```

make\_num

```
    ret += '<table class="collapse"><tr 

```

class=“odd\_border”)\>

- ’  
ret += ‘’ + show\_image(manufacture\_material.image\_name) +  
‘’  
ret += ‘’ + link\_to(manufacture\_material.name,  
manufacture\_material) + ’ x ’ + total\_num.ceil.to\_s + ‘&nbsp’  
ret += ‘
’  
else  
# Material has manufacture  
#ret += ‘make\_num=’ + manufacture.make\_num.to\_s + ‘  
’  
#ret += ‘req\_num=’ + manufacture\_material.required\_num.to\_s +  
‘  
’

```
    # Calculated total number of materials needed based how many 

```

needed  
make\_num = manufacture.make\_num.to\_f  
total\_num = total\_num.to\_f \*  
manufacture\_material.required\_num.to\_f / make\_num.to\_f  
time = manufacture.make\_time.to\_i \* total\_num.to\_i  
total\_time = total\_time + time

```
    ret += '<table class="collapse"><tr 

```

class=“even\_border”\>

- ’  
ret += ‘’ + show\_image(manufacture.image\_name) + ‘’  
ret += ‘’ + link\_to(manufacture.name, manufacture) + ’ x ’ +  
total\_num.ceil.to\_s + ‘&nbsp’  
ret += ‘(’ + time.to\_s + ’ minute(s) with ’ +  
show\_image(manufacture.tool.image\_name) + ‘’  
ret += ‘’ + link\_to(manufacture.tool.name, manufacture.tool)

- ‘)&nbsp’  
ret += ‘’

root\_id, manufacture.id) if manufacture.manufacture\_materials.length \> 0

```
    # Finished looping through all materials for this manufacture, 

```

resetting required number to 1  
total\_num = 1

```
    ret += '</li>'
  end

  end # End loop for materials in manufacture

  ret += '</ul>'

  ret += current_id.to_s + '<br>'
  ret += root_id.to_s + '<br>'

  if current_id == root_id
    ret += 'Total Time: ' + total_time.to_s + ' minute(s)<br>'
  end
end

```

end

line 55 is: ret += tree\_ul(manufacture, total\_num, make\_num,  
total\_time, root\_id, manufacture.id) if  
manufacture.manufacture\_materials.length \> 0

line 18 is: manufacture.manufacture\_materials.each do  
|manufacture\_material|

and the error message is:

TypeError in Manufactures#show

Showing manufactures/show.html.erb where line #10 raised:

can’t convert nil into String

Extracted source (around line #10):

7: \<%= link\_to @manufacture.tool.name, @manufacture.tool  
%\>)  
8:   
9:  
10: \<%= tree\_ul(@manufacture, 1, 1, @manufacture.make\_time,  
@manufacture.id.to\_i, @manufacture.id.to\_i) %\>  
11:  
12:   
  
13:

RAILS\_ROOT: /u1/app/wonderland-dev  
Application Trace | Framework Trace | Full Trace

app/helpers/manufactures\_helper.rb:55:in `+' app/helpers/manufactures_helper.rb:55:in `tree\_ul’  
app/helpers/manufactures\_helper.rb:18:in `tree_ul' app/helpers/manufactures_helper.rb:55:in `tree\_ul’  
app/helpers/manufactures\_helper.rb:18:in `tree_ul' app/helpers/manufactures_helper.rb:55:in `tree\_ul’  
app/helpers/manufactures\_helper.rb:18:in `tree_ul' app/views/manufactures/show.html.erb:10:in `\_run\_erb\_47app47views47manufactures47show46html46erb’  
app/controllers/manufactures\_controller.rb:16:in `show’

/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/associations/association\_proxy.rb:125:in  
`each' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/association_proxy.rb:125:in `send’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/associations/association\_proxy.rb:125:in  
`method_missing' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/association_collection.rb:162:in `method\_missing\_without\_paginate’  
vendor/plugins/will\_paginate/lib/will\_paginate/finder.rb:164:in  
`method_missing' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/association_proxy.rb:125:in `each’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/associations/association\_proxy.rb:125:in  
`send' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/association_proxy.rb:125:in `method\_missing’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/associations/association\_collection.rb:162:in  
`method_missing_without_paginate' vendor/plugins/will_paginate/lib/will_paginate/finder.rb:164:in `method\_missing’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/associations/association\_proxy.rb:125:in  
`each' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/association_proxy.rb:125:in `send’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/associations/association\_proxy.rb:125:in  
`method_missing' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/association_collection.rb:162:in `method\_missing\_without\_paginate’  
vendor/plugins/will\_paginate/lib/will\_paginate/finder.rb:164:in  
`method_missing' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/base.rb:637:in `send’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_view/base.rb:637:in  
`compile_and_render_template' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/base.rb:365:in `render\_template’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_view/base.rb:316:in  
`render_file' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1100:in `render\_for\_file’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/base.rb:858:in  
`render_with_no_layout' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:872:in `render\_with\_no\_layout’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/layout.rb:262:in  
`render_without_benchmark' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:51:in `render’  
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:51:in `render’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/mime\_responds.rb:131:in  
`send' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:131:in `custom’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/mime\_responds.rb:156:in  
`call' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:156:in `respond’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/mime\_responds.rb:150:in  
`each' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:150:in `respond’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/mime\_responds.rb:107:in  
`respond_to' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/base.rb:1158:in  
`perform_action_without_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call\_filters’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/filters.rb:689:in  
`perform_action_without_benchmark' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform\_action\_without\_rescue’  
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform\_action\_without\_rescue’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/rescue.rb:199:in  
`perform_action_without_caching' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:678:in `perform\_action’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/connection\_adapters/abstract/query\_cache.rb:33:in  
`cache' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/query_cache.rb:8:in `cache’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/caching.rb:677:in  
`perform_action' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `send’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/base.rb:524:in  
`process_without_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:685:in `process\_without\_session\_management\_support’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/session\_management.rb:123:in  
`process' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:388:in `process’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/dispatcher.rb:171:in  
`handle_request' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in `dispatch’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/dispatcher.rb:126:in  
`dispatch_cgi' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in `dispatch’  
/usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi\_handler.rb:101:in  
`process_request' /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi_handler.rb:149:in `with\_signal\_handler’  
/usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi\_handler.rb:99:in  
`process_request' /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi_handler.rb:77:in `process\_each\_request’  
/usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:612:in  
`each_cgi' /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in `each’  
/usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in  
`each_cgi' /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi_handler.rb:76:in `process\_each\_request’  
/usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi\_handler.rb:50:in  
`process!' /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi_handler.rb:24:in `process!’  
public/dispatch.fcgi:27

app/helpers/manufactures\_helper.rb:55:in `+' app/helpers/manufactures_helper.rb:55:in `tree\_ul’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/associations/association\_proxy.rb:125:in  
`each' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/association_proxy.rb:125:in `send’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/associations/association\_proxy.rb:125:in  
`method_missing' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/association_collection.rb:162:in `method\_missing\_without\_paginate’  
vendor/plugins/will\_paginate/lib/will\_paginate/finder.rb:164:in  
`method_missing' app/helpers/manufactures_helper.rb:18:in `tree\_ul’  
app/helpers/manufactures\_helper.rb:55:in `tree_ul' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/association_proxy.rb:125:in `each’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/associations/association\_proxy.rb:125:in  
`send' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/association_proxy.rb:125:in `method\_missing’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/associations/association\_collection.rb:162:in  
`method_missing_without_paginate' vendor/plugins/will_paginate/lib/will_paginate/finder.rb:164:in `method\_missing’  
app/helpers/manufactures\_helper.rb:18:in `tree_ul' app/helpers/manufactures_helper.rb:55:in `tree\_ul’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/associations/association\_proxy.rb:125:in  
`each' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/association_proxy.rb:125:in `send’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/associations/association\_proxy.rb:125:in  
`method_missing' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/associations/association_collection.rb:162:in `method\_missing\_without\_paginate’  
vendor/plugins/will\_paginate/lib/will\_paginate/finder.rb:164:in  
`method_missing' app/helpers/manufactures_helper.rb:18:in `tree\_ul’  
app/views/manufactures/show.html.erb:10:in  
`_run_erb_47app47views47manufactures47show46html46erb' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/base.rb:637:in `send’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_view/base.rb:637:in  
`compile_and_render_template' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/base.rb:365:in `render\_template’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_view/base.rb:316:in  
`render_file' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1100:in `render\_for\_file’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/base.rb:858:in  
`render_with_no_layout' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:872:in `render\_with\_no\_layout’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/layout.rb:262:in  
`render_without_benchmark' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:51:in `render’  
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:51:in `render’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/mime\_responds.rb:131:in  
`send' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:131:in `custom’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/mime\_responds.rb:156:in  
`call' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:156:in `respond’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/mime\_responds.rb:150:in  
`each' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/mime_responds.rb:150:in `respond’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/mime\_responds.rb:107:in  
`respond_to' app/controllers/manufactures_controller.rb:16:in `show’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/base.rb:1158:in  
`send' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `perform\_action\_without\_filters’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/filters.rb:697:in  
`call_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform\_action\_without\_benchmark’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/benchmarking.rb:68:in  
`perform_action_without_rescue' /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/benchmarking.rb:68:in  
`perform_action_without_rescue' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/rescue.rb:199:in `perform\_action\_without\_caching’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/caching.rb:678:in  
`perform_action' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/query\_cache.rb:8:in  
`cache' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:in `perform\_action’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/base.rb:524:in  
`send' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `process\_without\_filters’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/filters.rb:685:in  
`process_without_session_management_support' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:123:in `process’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/base.rb:388:in  
`process' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:in `handle\_request’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/dispatcher.rb:115:in  
`dispatch' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in `dispatch\_cgi’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/dispatcher.rb:9:in  
`dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi_handler.rb:101:in `process\_request’  
/usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi\_handler.rb:149:in  
`with_signal_handler' /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi_handler.rb:99:in `process\_request’  
/usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi\_handler.rb:77:in  
`process_each_request' /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:612:in `each\_cgi’  
/usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in `each' /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in `each\_cgi’  
/usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi\_handler.rb:76:in  
`process_each_request' /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi_handler.rb:50:in `process!’  
/usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/fcgi\_handler.rb:24:in  
`process!’  
public/dispatch.fcgi:27

Request

Parameters:

{“id”=\>“247”}

Show session dump

* * *

:csrf\_id: af9209d97a6677f0461592b6d1f45741  
:return\_to:  
:user\_id: 1  
flash: !map:ActionController::Flash::FlashHash {}

Response

Headers:

{“cookie”=\>[],  
“Content-Type”=\>“text/html”,  
“Cache-Control”=\>“no-cache”}

---

<div class="post-metadata">

**Author:** ![skirkpatrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@skirkpatrick](https://www.ruby-forum.com/u/skirkpatrick)\
**Post date:** [June 8, 2008, 4:02pm UTC](https://www.ruby-forum.com/t/trouble-with-if-statement-in-helper-function/139859/7 "2008-06-08T16:02:40Z")

</div>

Thorsten M. wrote:

> yes, that’s obvious.  
> The last lines are the if statement. (As long as it fails). This will  
> return nil and then the recursive call in line 55 fails. (Otherwise it  
> returns ret and is ok)
> 
> Since it’s not sure, that ret contains anything at all, something like  
> that should work:
> 
> ret ||= “”
> 
> as last line. If ret contains something, that’ll be returned, if not  
> it’ll return an empty string.  
> This would make sure, that the method returns a string in any case.

thank you so much!! you just made my day!! it’s working now.
