I have a standard Rails 2.3.5 app with a model called Post. Post has an attribute called url, and the following getter is defined:
def url
p = 'http://'
u = self[:url]
u.starts_with?(p) ? u : "#{p}#{u}"
end
If I load up script/console
, I can do Post.first.url
and get the desired result (e.g. it returns http://foo.com if the attribute's true value is foo.com)
However, if I have a form_for
block, and do something like form.text_field :url
, it will not return the url with http:// prefixed; rather, it simply returns foo.com
How does form_for access attributes on ActiveRecord models? It seems to bypass any overloaded getters.