I wouldn't be in favour of this - purely because I'm generally against adding instance methods to ActiveRecord::Base in case they override attributes defined on the table. For example, a photography studio may have a photos table which imports from somewhere and has a "model_name" column.
I don't see the issue with having it on the class myself. Cheers, Andy *Andy Jeffries* Ruby on Rails, RubyMotion, jQuery Developer & Taekwondo 6th Dan Instructor andyjeffries.co.uk +44 7939 164853 @andyjeffries <http://twitter.com/andyjeffries> fb.com/andyjeffries <http://facebook.com/andyjeffries> On 30 May 2014 21:48, Amiel Martin <[email protected]> wrote: > Yes, please! > > > > > On Fri, May 30, 2014 at 11:11 AM, Jeremy Friesen < > [email protected]> wrote: > >> Following up on https://github.com/rails/rails/issues/15428, with >> adjustments. >> >> Throughout the Rails code there are a few references to >> `object.class.model_name`. Instead of always pushing this up to the class, >> it makes sense to me that we ask the model for its model_name. >> >> This might obviate the need for the dubious >> ActionController::ModelNaming#model_name_from_record_or_class, >> https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/model_naming.rb >> >> >> >> >> module ActionController >> module ModelNaming >> >> >> # Converts the given object to an ActiveModel compliant one. >> >> >> >> def convert_to_model(object) >> object.respond_to?(:to_model) ? object.to_model : object >> >> >> end >> >> def model_name_from_record_or_class(record_or_class) >> >> >> (record_or_class.is_a?(Class) ? record_or_class : >> convert_to_model(record_or_class).class).model_name >> >> >> end >> end >> >> >> end >> >> >> Example: >> >> >> class Foo >> extend ActiveModel::Naming >> def model_name >> class.model_name >> endend >> Foo.respond_to?(:model_name)=> true >> Foo.new.respond_to?(:model_name)=> true >> Foo.model_name == Foo.new.model_name=> true >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Core" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/rubyonrails-core. >> For more options, visit https://groups.google.com/d/optout. >> > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.
