I want to share a partial between 2 or more controllers. I have a "location" partial that I want users to enter "Address, City, State, Zip" information in however I have "Payees", "Institution", and "Event" models that can have "location" information stored with them. Since I don''t want to duplicate the partial across each controller, I''ve placed the partial in a "shared" folder however I''m having problems rendering it with the appropriate model object. A sample of my renders look like this: <%= render :partial => ''shared/location'', :object => @payee %> A sample of my partial looks like this: <%= location.text_field :address, :size => 60 %> Obviously rails is complaining that the object is not related to a form since I''m not using "form_for" or "fields_for" (see below for error). "undefined method `text_field'' for #<Payee:0x4472530>" How can I make this happen while keeping it DRY? -- 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 -~----------~----~----~----~------~----~------~--~---
On 2 Dec 2008, at 17:24, Corey Murphy wrote:> > I want to share a partial between 2 or more controllers. > > I have a "location" partial that I want users to enter "Address, City, > State, Zip" information in however I have "Payees", "Institution", and > "Event" models that can have "location" information stored with them. > Since I don''t want to duplicate the partial across each controller, > I''ve > placed the partial in a "shared" folder however I''m having problems > rendering it with the appropriate model object. > > A sample of my renders look like this: > <%= render :partial => ''shared/location'', :object => @payee %> > > A sample of my partial looks like this: > <%= location.text_field :address, :size => 60 %> > > Obviously rails is complaining that the object is not related to a > form > since I''m not using "form_for" or "fields_for" (see below for error). > > "undefined method `text_field'' for #<Payee:0x4472530>" >Could you just call fields_for and pass through the yielded object instead of passing through @payee ? Fred> How can I make this happen while keeping it DRY? > -- > 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 2 Dec 2008, at 17:24, Corey Murphy wrote: > >> >> "undefined method `text_field'' for #<Payee:0x4472530>" >> > Could you just call fields_for and pass through the yielded object > instead of passing through @payee ? > > FredHow would I pass through the yielded object? I can''t write "fields_for :payee" since this partial is used by the other two models (events, institutions) as well. When trying the following . . . <%= render :partial => ''shared/location'', :object => @payee %> <% fields_for :location do |l| %> <%= l.text_field :address, :size => 60 %> <% end %> The rendered HTML is showing the field ids as such "location_address", when they need to ultimately be "payee_address" I''m obviously missing something here. -- 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 -~----------~----~----~----~------~----~------~--~---
On 2 Dec 2008, at 18:35, Corey Murphy wrote:> > Frederick Cheung wrote: >> On 2 Dec 2008, at 17:24, Corey Murphy wrote: >> >>> >>> "undefined method `text_field'' for #<Payee:0x4472530>" >>> >> Could you just call fields_for and pass through the yielded object >> instead of passing through @payee ? >> >> Fred > > How would I pass through the yielded object? I can''t write > "fields_for > :payee" since this partial is used by the other two models (events, > institutions) as well. > > When trying the following . . . > > <%= render :partial => ''shared/location'', :object => @payee %> > > <% fields_for :location do |l| %> > <%= l.text_field :address, :size => 60 %> > <% end %> > > The rendered HTML is showing the field ids as such "location_address", > when they need to ultimately be "payee_address" >I was actually thinking of something along the lines for <% fields_for @payee do |f| %> <%= render :partial=> ''shared/location'', :object => f %> <% end >%> I''m obviously missing something here. > -- > 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> I was actually thinking of something along the lines for > <% fields_for @payee do |f| %> > <%= render :partial=> ''shared/location'', :object => f %> > <% end >%I follow you now. A much simpler way of doing it and it solved my problem. Thanks once again Fred -- 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 -~----------~----~----~----~------~----~------~--~---