On 7/10/06, Jonathan G. [email protected] wrote:
So whats the best way to do this (as I dont think models are visible
from within application.rb)?
application.rb is a controller that all other controllers inherit from.
Models are just as visible in the application controller as any other.
There are a couple of ways to do this. Helper methods, before_filters
couple of more obscure ones.
Probably using both would be benificial. You can define the method in
controller and then tell it to act as a helper method as well. Then you
it in the controller and the views.
First, use a before_filter in the application controller
class ApplicationController < ActionController::Base
@variable = MyModel.find(:first)
This will provide a method some_variable to both views and controllers.
@variable will be set every time the controller is fired up.
Hope this helps