Newbie Q: Making code accessible by controller regardless of

Hello,

I have a model:

review.rb

class Review < ActiveRecord::Base
def self.published
find(:all,
:conditions => “she_published = TRUE and he_published = TRUE
and date_to_be_published <= now()”)
end
end

And a controller:

display_controller.rb

class DisplayController < ApplicationController
def index
@published_reviews = Review.published
end

def show
@review = Review.find(params[:id])
@published_reviews = Review.published
end

def about
@published_reviews = Review.published
end
end

And part of my layout:

display.rhtml

    <% for review in @published_reviews %>
      <%= link_to review.name, :controller => "display", :action =>

“show”, :id => review.id %>


<% end %>

Right now the only way I can get things to work is to put the line
@published_reviews = Review.published
in each def

Is there a place I can put this line just once so it’s accessible by
the layout, no matter what the action?

Thanks,

Sean

before_filter :get_published_reviews

def get_published_review
@published_reviews = Review.published
end

thanks for your help with this. this worked for me.

oops, typo

…def get_published_reviews…

If you put that at the top of a controller it will be available in all
the actions (if you put it in the application controller it will be
available to all actions in all controllers).