I have this one partial _ownerselect.rhtml in my Computers Controller that has an instance var @computers. I call the partial like: :partial =>'' ownerselect'', :object => computers>From inside the partial computers.location does not work. The onlyworking solution is ownerselect.location Why on earth has the name of the partial replace that of the object passed to it? Thanx! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
when using the :object option, the name of the object in the partial takes the name of the partial. its part of the DRY principal in that you can reuse the partial without requiring the partial to know the name of the object you are passing to it. think of it like a method call. the method itself is not aware of the name of the parameter on the outside of the function. def mymethod(arg) # isn''t aware of the name of the argument outside the function end x = 1 mymethod(x) say i have a partial named ''_people_list.rhtml'' in one action i want to list all the people @people = Person.find(:all) render :partial => "people_list", :object => @people in another action i want to list just blond_haired_people @bh_people = Person.find(:all, :conditions => "hair_color = ''blonde''") render :partial => "people_list", :object => @bh_people then in my partial i just use people_list to refer to the object that was passed in and it will always work. On 1/19/07, Josh <josh.m.sharpe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have this one partial _ownerselect.rhtml in my Computers Controller > that has an instance var @computers. > > I call the partial like: > > :partial =>'' ownerselect'', :object => computers > > >From inside the partial computers.location does not work. The only > working solution is ownerselect.location > > Why on earth has the name of the partial replace that of the object > passed to it? > > Thanx! > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Josh wrote:> I have this one partial _ownerselect.rhtml in my Computers Controller > that has an instance var @computers. > > I call the partial like: > > :partial =>'' ownerselect'', :object => computers > >>From inside the partial computers.location does not work. The only > working solution is ownerselect.location > > Why on earth has the name of the partial replace that of the object > passed to it?It''s not a replace, it''s a local vriable in the partial, named after the partial, which has been assigned the :object passed to it. This allows the partial to be ''self-contained'', and can be used from many controllers etc with different variables. Just like passing a parameter to a method... A. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---