I am trying to put a random rss feed in the main (application) view. The code works if I surf to /feed/, but if I use the same partial outside of views/feeds/ I get errors about nil objects. It seems that the partial does not automatically use it''s controller. I hope this makes sense. --~--~---------~--~----~------------~-------~--~----~ 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
2008-Mar-19 08:48 UTC
Re: How to use a controller/model in a different view
On 19 Mar 2008, at 02:53, tresero wrote:> > I am trying to put a random rss feed in the main (application) view. > The code works if I surf to /feed/, but if I use the same partial > outside of views/feeds/ I get errors about nil objects. It seems that > the partial does not automatically use it''s controller. >Partials and views don''t belong to a controller in particular (except in the sense that their location on disk implies the controller that normally uses them). Your partial probably depends on the controller having setup some instance variable which you are setting up in your FeedController, but not elsewhere. Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Shai Rosenfeld
2008-Mar-19 10:09 UTC
Re: How to use a controller/model in a different view
> The code works if I surf to /feed/, but if I use the same partial > outside of views/feeds/ I get errors about nil objects. It seems thatjust pass it the parameter it needs, no? (this will create a local variable, though, just to be a little more precise) - render :partial => ''feeds/partialname'', :locals => { :var => @var } -- 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 -~----------~----~----~----~------~----~------~--~---
Unfortunately that does not work. It appears that calling a partial does not initialize. I have: @feed = Feed.find_by_handle(''handle'') @feed.sync if @feed in my application controller. in application view: <%= render :partial => ''feeds/rss'', :locals => { :feed => @feed } %> Still getting a nil error: You have a nil object when you didn''t expect it! The error occurred while evaluating nil.url Extracted source (around line #1): Feed: <a href="<%= @feed.url -%>"><%= @feed.handle -%></a><br/> Title: <%= @feed.title -%><br/> Description: <%= @feed.description -%><br/> So it is never initializing feed. On Mar 19, 2:09 am, Shai Rosenfeld <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > The code works if I surf to /feed/, but if I use the same partial > > outside of views/feeds/ I get errors about nil objects. It seems that > > just pass it the parameter it needs, no? (this will create a local > variable, though, just to be a little more precise) - > > render :partial => ''feeds/partialname'', :locals => { :var => @var } > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Hi, On Thu, Mar 20, 2008 at 1:16 PM, tresero <jon-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote:> > Unfortunately that does not work. It appears that calling a partial > does not initialize. > > I have: > @feed = Feed.find_by_handle(''handle'') > @feed.sync if @feed > in my application controller. > > in application view: > > <%= render :partial => ''feeds/rss'', :locals => { :feed => @feed } %> > > > Still getting a nil error: > You have a nil object when you didn''t expect it! > The error occurred while evaluating nil.url > > So it is never initializing feed.It''s initializing "feed", not "@feed". Change your partial to use a local variable instead, change other places that render the partial to provide feed as a local variable, and you should be good. ~ j. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---