Forum: Ruby on Rails acess local variables from helper?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ddd11872984864786c14992b99ab4d2d?d=identicon&s=25 Alan Bullock (Guest)
on 2006-04-13 11:30
(Received via mailing list)
if I call a helper method from inside a partial, it doesn't appear to
have
access to the partials local variables. is there a way to make them
avilable
without passing them as parameters?

here's a simple example

# in the view
<%= render :partial => "my_partial", :locals => :value => 2%>

# _my_partial.rhtml  - raises "undefined local variable or method
`value'"
<%= show_value %>

# helper method
def show_value
    value
end
43ec5998360a0cc21b51afef1781e9c0?d=identicon&s=25 Daniel Higginbotham (Guest)
on 2006-04-13 11:40
(Received via mailing list)
My first thought is that you could make value an attribute (though that
means they're no longer local), so you'd have

# in the view
<% @value = 2 %>
<%= render :partial => "my_partial" %>

# _my_partial.rhtml  - raises "undefined local variable or method
`value'"
<%= show_value %>

# helper method
def show_value
    @value
end


But to me it seems better to just pass your values in as parameters.

Daniel
Ddd11872984864786c14992b99ab4d2d?d=identicon&s=25 Alan Bullock (Guest)
on 2006-04-13 11:58
(Received via mailing list)
"Daniel Higginbotham"
<daniel@flyingmachinestudios.com> wrote in message
news:20060413093847.C5010111E21@spunkymail-a3.dreamhost.com...
> My first thought is that you could make value an attribute (though that
> means they're no longer local), so you'd have

I'm not sure if instance variables are practical in this case because
the
partial gets rendered many times (as a collection). Thanks for your
suggestion though.
This topic is locked and can not be replied to.