[Rails] Use of Super or how to get the calling object.
Class User
has_many :settings, :class_name => "UserSetting", :foreign_key => "user_id"
Class UserSetting
belongs_to :user
In UserSetting i have
class << self
def set(name, value)
setting = [here i need the calling user object].settings.find_or_initialize_by_name(name)
end
end
what i want is to be abel to make a call like:
user = User.find(1)
user.settings.set("test", "test")
Is this possible or am i just way off ?
-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/V8fTT3CSZkcJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home