On 24 February 2011 08:21, Mauro <[email protected]> wrote:
> If I do something like this:
>
> [snip controller code]
>
> The fetch_operator action is always executed, before every action in
> every controller?
> I'd want to fetch the operator only at start and not before every
> action but I need to have it available on every view and controller.
Are you then using the @current_operator variable in places in your
controller? (like "if @current_operator.name == 'fred'..."?)
If so, instead use a helper method to return the operator (and
populate it if necessary), rather than the filter method:
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter RubyCAS::Filter
include SessionsHelper
helper_method :current_operator
def current_operator
@current_operator ||= fetch_operator
end
private
def fetch_operator
session[:cas_user] &&
Operator.find_by_uid(session[:cas_user])
rescue ActiveRecord::RecordNotFound
redirect_to("/404.html")
end
end
--
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.