Acess local variables from helper?


#1

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


#2

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


#3

“Daniel H.”
removed_email_address@domain.invalid wrote in message
news:removed_email_address@domain.invalid…

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.