Say there is the following model with a database column
'reference_id' (of type string).
class Post < ActiveRecord::Base
def reference_id
if self.new_record?
return "test"
else
return self[:reference_id]
end
end
end
Somewhere in the form one would do:
builder.text_field :subject
In Rails 3.0.0 the behaviour was that when i render "new" with a
new record assigned, the text_field would get the value "test"
(because that is what the method returns).
Now the text_field will be empty. Rails probably just reads the
attribute (which is still nil) and doesn't call the method to fill
out the value.
I used that technique to provide my own attribute methods for
default values etc. Now i always have to provide ":value =>
@post.reference_id" to the text_field, so that i get the same
result.
Is this supposed to be the new behaviour? Or was that an
unintentional change / bug?
I hope this example is clear enough!