Where to put this to have access from everywhere

I have this

class Pic < ActiveRecord::Base
def self.active_pics
find(:all, :conditions => [“thumbnail is NULL AND active = 1”])
end
end

in my pic.rb model file.

I have an area on my site which uses a different layout file
(pic.html.erb). Within the layout file I render a special partial
(_pics_nav.html.erb):

<% for pic in @pics %>
<%= pic.description %>
<% end %>

So I get a nil object.

Where tu put this code so I have access within every layout file and
every partial?

Thanx


Jochen K.

On 26 Oct 2007, at 11:56, Jochen K. wrote:

Where tu put this code so I have access within every layout file and
every partial?

Don’t rely on the instance variable :
<%= render :partial => ‘/shared/pics_nav’, :object => Pic.active_pics %>

If this is quite common, i’d stick something in application helper

def render_pic_nav_bar
render :partial => ‘/shared/pics_nav’, :object => Pic.active_pics %>
end

and then you just do <%= render_pic_nav_bar%> when you need it.
Fred

Frederick C. schrieb:

So I get a nil object.
def render_pic_nav_bar
render :partial => ‘/shared/pics_nav’, :object => Pic.active_pics %>
end

and then you just do <%= render_pic_nav_bar%> when you need it.
Fred

Wow! That easy!

Thanx a lot!!


Jochen K.