Try a before_filter.  In your ApplicationController add the following:

    before_filter :load_mightlike

    private
      def load_mightlike
        @mightlike = Vehicle.random
      end

Darian Shimy
--
http://www.darianshimy.com
http://twitter.com/dshimy


On Mon, Nov 16, 2009 at 10:49 PM, brianp <[email protected]> wrote:
>
> 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?
> >

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to