Ruby on Rails: errors.add_to_base vs. errors.add

前端 未结 3 2065
失恋的感觉
失恋的感觉 2021-01-31 02:00

I have read that errors.add_to_base should be used for errors associated with the object and not a specific attribute. I am having trouble conceptualizing what this means. Cou

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-31 02:43

    It's worth noting (since this shows up in the search engines, which is how I found it) that this is deprecated. The Rails 3 way of doing it is:

    errors[:base] << "Error message"    
    

    or

    errors.add(:base, "Error message")
    

    http://apidock.com/rails/ActiveRecord/Errors/add_to_base
    http://apidock.com/rails/v3.2.8/ActiveModel/Errors/add

提交回复
热议问题