How to use a controller/model in a different view

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.

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

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 }

Hi,

On Thu, Mar 20, 2008 at 1:16 PM, tresero [email protected] wrote:

<%= 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.

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: <%= @feed.handle -%>

Title: <%= @feed.title -%>

Description: <%= @feed.description -%>

So it is never initializing feed.

On Mar 19, 2:09 am, Shai R. [email protected]