How to access the object bound to form in partial?

Hi,

In a partial, how do I access the ActiveRecord object that's bound to a
form?

<%= f.text_field :name %>
<% if f.(something).new_record? %>
...
<% end %>

I want to know if the object is new record or not.
I can pass the object itself using :locals, but I want to make it DRY.

Thanks.

Sam

Use if @foo.new_record?

f.something won't respond to new_record?

Hi Greg,

Greg Donald wrote:

In a partial, how do I access the ActiveRecord object that's bound to a
form?

<%= f.text_field :name %>
<% if f.(something).new_record? %>

Use if @foo.new_record?

Yes, I know that.
However, I am not sure if I can assume that the partial knows @foo.
As partial views are supposed to be shared among controllers, I want to
minimize the coupling of partial and controller.

I am not sure, though.

Thanks.

Sam

Then don't assume, test for it.

if @foo && @foo.new_record?

f.object if my memory serves me correctly.

Fred

Hi Frederick,

Frederick Cheung wrote: