Instance or local vars for field helpers in partial template


I’m getting confused.

If I have a view (.rhtml), I can use a field helper like:

<%= text_field :mymodel, :attribute %>

This uses the value from @mymodel.attribute

Now, if I am rendering a template normally (i.e. not partial), I would
expect @mymodel to be a model object defined as an instance variable in
the controller.

However, if I am rendering a partial template, I either have:

render :partial => ‘mything’, :object => @mymodel
render :partial => ‘mything’, :collection => @mymodelcollection

Now, inside the template, the @mymodel object is available as the
local variable mything (same as template name).

If I have a field helper, I cannot now use:

text_field :mything, :attribute

because text_field expects @mything (an instance variable).

I can get around this my putting at the top of my partial template:

<% @mything = mything %>

but this seems a little clunky and un-Ruby-ish. Is there a better way?




On 5/4/06, Julian G. removed_email_address@domain.invalid wrote:

the controller.
If I have a field helper, I cannot now use:

Not that I’m aware of. That’s the way DHH told me to do it. Heh.