Currently, to set some default values, but also keep any values that the
user specifies to new, i''m doing this:
def initialize(*params)
defaults = {:resources => true,
:lessons => true,
:courses => true,
:sort_by => "name",
:term => "",
:kinds => ["0"],
:fields => ["0"],
:subject_families => ["0"],
:subject_family_members => ["0"]
}
params[0] = defaults.merge(params[0] || {})
super(*params)
end
It works but seems a bit dirty. Is there a nicer way? I know that the
after_intialize callback is called after a record is retrieved from the
db as well (i never understood the logic behind this) so i avoided
using that.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---