Take the 2-minute tour ×

It appears that when I call a helper method from one of my views, I am unable to set any new local variables. Name doesn't matter - everything I set is nil.

From most views, everything is fine:

editable = true
html << 'Editable: ' + editable.to_s

Outputs Editable: true

However, from one of my partials, the output is Editable: indicating nil.

I'm attempting to isolate what is different about this particular view file - posting swaths of files won't help anyone.

With this information (I know it's not a lot), can anyone tell me why I might not be able to set local variables in a helper method?

share|improve this question
Is it possible there is a conflict with the name of the partial? Rails creates a local variable named after the model: guides.rubyonrails.org/… But even then, you should be able to override it. –  shioyama Dec 21 '12 at 16:58
A conflict as in there's more than 1 by the same name? I specify the folder from the render :partial and there's no other files by that name. I think it may be related to this issue:stackoverflow.com/questions/2128406/…. I'm debugging ivars from the different views and if that doesn't turn something up, I'll move the helper code to a partial which is where it should be anyways. –  Archonic Dec 21 '12 at 17:21
Sorry never mind, misread the question. –  shioyama Dec 21 '12 at 18:54
add comment

1 Answer

up vote 0 down vote accepted

This was a 'stupid mistake' on my part but I can't entirely blame myself. Rails behaved very oddly.

editable = true came just after this line in my code:

target_str == '#overview' ? target_str = '#section' : #nothing

It's weird, I know. I was getting errors without the :. I've changed the line to this

target_str = '#section' if target_str == '#overview'

It should do the same thing IMO, but of course doesn't. Despite being a 1 line if, it was including the next statement which was editable = true. This explains why it was only happening for 1 of my views as well - the only one where the statement evaluated as true.

share|improve this answer
add comment

Your Answer


