In my attempt to add AM:Dirty to my model I realized that AM#AttributeMethods is a bit imperfect. It''s impossible to generate attribute methods step-by-step in DataMapper-like manner. class Model include ActiveModel::Dirty def self.property(name, klass = String) define_property_accessors(name, klass) # This method will be called once, because of https://github.com/rails/rails/blob/master/activemodel/lib/active_model/attribute_methods.rb#L263 define_attribute_methods([name]) end end class Article < Model property :title property :body property :published_at, Time end In the above example, attribute methods will be defined just for :title. I don''t see any nice workaround. So what is the purpose of AttributeMethods#attribute_methods_generated? I can''t imagine any use case for this. What about removing it entirely and providing #define_attribute_method(s) with ability to call it multiple times? Am I missing something? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Hey Alex, if you want go ahead and try a fix ;). On Sat, Feb 5, 2011 at 4:37 AM, Alex <alexander.uvarov@gmail.com> wrote:> In my attempt to add AM:Dirty to my model I realized that > AM#AttributeMethods is a bit imperfect. It''s impossible to generate > attribute methods step-by-step in DataMapper-like manner. > > class Model > include ActiveModel::Dirty > > def self.property(name, klass = String) > define_property_accessors(name, klass) > > # This method will be called once, because of > https://github.com/rails/rails/blob/master/activemodel/lib/active_model/attribute_methods.rb#L263 > define_attribute_methods([name]) > end > end > > class Article < Model > property :title > property :body > property :published_at, Time > end > > In the above example, attribute methods will be defined just > for :title. I don''t see any nice workaround. > > So what is the purpose of > AttributeMethods#attribute_methods_generated? I can''t imagine any use > case for this. What about removing it entirely and providing > #define_attribute_method(s) with ability to call it multiple times? Am > I missing something? > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Done. Ticket with patch https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6428 On Feb 7, 5:46 pm, Santiago Pastorino <santi...@wyeworks.com> wrote:> Hey Alex, if you want go ahead and try a fix ;).-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Could anyone take a look at this ticket? https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6428 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Reasonably Related Threads
- Rails 3 / ActiveModel for Credit Card information?
- Overriding AR read/write_attribute - Overridden write_attribute Is Never Called
- Proposal for a new ActiveModel::Errors structure
- ActiveRecord::Validator vs ActiveModel::Validator
- undefined method `singular_route_key' for "User":ActiveModel::Name