Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
Extracted attributes assingment from ActiveRecord to ActiveModel #10776
Now you are able to do:
class Feedback include ActiveModel::AttributeAssignment attr_accessor :email, :subject, :body end f = Feedback.new f.assign_attributes( :email => "email@example.com", :subject => "Hello", :body => "The app dont work for me" )
This is just a proof of concept PR.
There is still some todos:
I am gonna add them if this will be approved to merge in.
Updated the PR:
I wonder if, once all non-db-specific logic (including recent one such as the user-facing casting half) is extracted to AM, it would make sense to have a more full-featured out-of-the-box implementation of active model for those that want it to behave not just as a form object but as much as a full AR as possible, except not persisted. That means all the same validations/errors, attribute assignment, casting, etc.
Perhaps call it
The name `ActiveModel::AttributeAssignment::UnknownAttributeError` is too implementation specific so let's move the constant directly under the ActiveModel namespace. Also since this constant used to be under the ActiveRecord namespace, to make the upgrade path easier, let's avoid raising the former constant when we deal with this error on the Active Record side.