This project is archived and is in readonly mode.

#5198 ✓stale
Robert Pankowecki

undefined method 'i18n_scope' raised by ActiveModel::Errors when validated model is not extended with ActiveModel::Translation. Incorrect documentation about ActiveModel::Errors class.

Reported by Robert Pankowecki | July 26th, 2010 @ 03:33 PM

This is extract from ActiveModel::Errors documentation:

  # A minimal implementation could be:
  # 
  #   class Person
  #   
  #     # Required dependency for ActiveModel::Errors
  #     extend ActiveModel::Naming
  # 
  #     def initialize
  #       @errors = ActiveModel::Errors.new(self)
  #     end
  #   
  #     attr_accessor :name
  #     attr_reader   :errors
  #   
  #     def validate!
  #       errors.add(:name, "can not be nil") if name == nil
  #     end
  #   
  #     # The following methods are needed to be minimally implemented
  #
  #     def read_attribute_for_validation(attr)
  #       send(attr)
  #     end
  #   
  #     def ErrorsPerson.human_attribute_name(attr, options = {})
  #       attr
  #     end
  #   
  #     def ErrorsPerson.lookup_ancestors
  #       [self]
  #     end
  #   
  #   end
  #
  # The last three methods are required in your object for Errors to be
  # able to generate error messages correctly and also handle multiple
  # languages.  Of course, if you extend your object with ActiveModel::Translations
  # you will not need to implement the last two.  Likewise, using
  # ActiveModel::Validations will handle the validation related methods
  # for you.

Problem 1: I think it should state that Person.human_attribute_name and Perons.lookup_ancestors are necessary. They should be defined for Person class, not for ErrorsPerson class.

Problem 2: Implementing those methods on Person class is not enough. When you do so it leads to the exception:

undefined method `i18n_scope' for Person:Class

activemodel (3.0.0.beta4) lib/active_model/errors.rb:261:in `block in generate_message'
activemodel (3.0.0.beta4) lib/active_model/errors.rb:260:in `map'
activemodel (3.0.0.beta4) lib/active_model/errors.rb:260:in `generate_message'
activemodel (3.0.0.beta4) lib/active_model/errors.rb:182:in `add'

Problem 3: To walk around second problem the class should be extended with ActiveModel::Translation, not ActiveModel::Translations as the documentation states.

Comments and changes to this ticket

  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer November 7th, 2010 @ 04:54 PM

    • Tag cleared.
    • Importance changed from “” to “Low”

    Automatic cleanup of spam.

  • Santiago Pastorino

    Santiago Pastorino February 9th, 2011 @ 12:32 AM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 9th, 2011 @ 12:32 AM

    • State changed from “open” to “stale”

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>

Pages