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 want to know if the object is new record or not.
f.object if my memory serves me correctly.
That’s right.
The problem is that if I pass a string to the form_for, f.object is nil.
It’s valid only when I pass an object.
Probably I can use it with f.object_name.
Thanks.
Sam
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.