Hi, I read some articles about why partials should not have instance variables in them. But in "Ruby on Rails 3 Tutorial" the author starts with this partial: View: <%= form_for(@user) do |f| %> <%= render ''shared/error_messages'' %> Partial: <% if @users.errors.any? %> ... ... I thought removing the @user instance variable from the partial would have involved doing this: View: <%= form_for(@user) do |f| %> <%= render ''shared/error_messages'', :user => @user %> Partial: <% if user.errors.any? %> But the author actually does this: View: <%= form_for(@user) do |f| %> <%= render ''shared/error_messages'', :object => f.object %> Partial: <% if object.errors.any? %> The author says that f.object is "the object corresponding to the form variable f". Is that right? What''s f then? Based on the way f.object is used, it appears to be equivalent to @user. Is it? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
7stud -- wrote in post #1014561:> But the author actually does this: > > View: > <%= form_for(@user) do |f| %> > <%= render ''shared/error_messages'', :object => f.object %> > > Partial: > <% if object.errors.any? %> > > > The author says that f.object is "the object corresponding to the form > variable f". Is that right? What''s f then? Based on the way f.object > is used, it appears to be equivalent to @user. Is it?The variable f is a reference to the FormBuilder object, which in turn holds a reference to the object assigned to it (form_for @user) so f.object would be a reference to @user. The use of :object => f.object would ensure that the object passed into the partial is truly the object referenced by the FormBuilder f. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thats what I figured. Thanks. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.