This project is archived and is in readonly mode.
Allow classes using validation to specify how attributes should be read
Reported by Jamie Hill | July 22nd, 2009 @ 01:13 AM | in 2.x
This patch adds a hook method to validations allowing a class to define how it's attributes should be acquired. This is useful should the class not use the default of having a method for each attribute and instead store values in a hash e.g.
class MyClass
include ActiveModel::Validations
def initialize(data = {})
@data = data
end
def []=(key, value)
@data[key] = value
end
private
def value_for(key)
@data[key]
end
end
By overriding the value_for method you have control over how attribute values are retrieved.
As Rails 3 is all about not having to hack the framework and instead provide hooks I believe this is a great addition an have use-cases right away.
Comments and changes to this ticket
-
José Valim August 8th, 2009 @ 11:41 AM
- State changed from new to duplicate
Duplicated of #2936 (which was already committed).
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>