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

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 Cheung schrieb:

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?

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

Wow! That easy!

Thanx a lot!!