现在,我不确定这是什么数据结构......它似乎是两个命名哈希的哈希,@ base和@messages。
#<ActiveModel::Errors:0x00000103a9cc80 @base=#<User id: nil, first_name: "Jimmy", last_name: "Thehat", profile_name: "Jimbohatboy", email: "awesomedog@hotmail.co.uk", encrypted_password: "$2a$04$MX40ryz4CU2jRuE4Pfy5.eRUz3rRZkmsvw7FXQyE6Bj1...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, confirmation_token: nil, confirmed_at: nil, confirmation_sent_at: nil, unconfirmed_email: nil, failed_attempts: 0, unlock_token: nil, locked_at: nil, created_at: nil, updated_at: nil>, @messages={}>
我知道如何在键控条目中打印数据,但不知道如何打印。我怎么能迭代@messages哈希?
答案 0 :(得分:1)
它是一个ActiveModel :: Errors对象(正如它所说)。在此处查找方法列表:http://api.rubyonrails.org/classes/ActiveModel/Errors.html
例如:
obj.full_messages.each { |error| puts error }