Instead of:
#Do Something...
end
end
Do:
after_initialize :do_something
#Do Something...
end
end
Update 13/06/07:
Using named callbacks better conveys your intention, making your code more readable.
Similar article on The Rails Way
class MyClass
def after_initialize
#Do Something...
end
end
class MyClass
after_initialize :do_something
def do_something
#Do Something...
end
end
class MyClass < ActiveRecord::Base
def initialize(params)
@params = params
end
end
my_object = MyClass.new(:params => params)
my_object.save
MyClass.create :params => params
I dont think the explanation of 'selection lists' in Agile Web Development with Rails(1st ed) is very clear. It mentions:
select(:variable, :attribute, choices, options, html_options)
@variable.attribute
select(:my_object, :method, choices, options, html_options)
def action
@my_object = MyClass.new
@my_object.method = params[:my_object][:method]
end
My setup was:
MySQL Table name: TABLENAME
Rails Model name: TableName