Common variable.

Hey Everyone,

At the bottom of my site layout I have a suggested item box. This box is at the bottom of everypage but the admin/manage section.

I tried using:

class ApplicationController < ActionController::Base     @mightlike = Vehicle.random end

then in the view for vehicles:

// vehicles.html.erb <dt>Make:</dt><dd><%=h @mightlike.make %></dd>

It works fine if i add "@mightlike = Vehicle.random" in:

class VehiclesController < ApplicationController   def index     @vehicles = Vehicle.find_all_by_market_status('available')     @mightlike = Vehicle.random   end end

But that restricts it to the index on the vehicle controller and I need it in almost every view being controlled by every controller. Whats the best way to do that?

Try a before_filter. In your ApplicationController add the following:

    before_filter :load_mightlike

    private       def load_mightlike         @mightlike = Vehicle.random       end

Darian Shimy

worked perfect, thank you kindly =)