I have fixed the problem of getting the organisation_id into all the
records without hundreds of assignements in controllers...
I have an observer:
class BaseTableObserver < ActiveRecord::Observer
cattr_accessor :current_organisation_id
def before_validation(base_table)
if base_table.organisation_id.blank? && !
@@current_organisation_id.blank? #only do it if its not already set
base_table.organisation_id=@@current_organisation_id
end
end
end
And the class variable @@current_organisation_id is set in the
ApllicationController in a before filter.
This works..
I assume that since Ruby is single threaded that it is safe to use the
Class/Static variable?
Cheers
George
PS Using with_scope in around_filters appears to be a bit of a
controversial subject!
As does accessing session type variables from models. But in this case
I am happier with this solution than lots of separate assignments
--
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.