Rails and Devise killed validation errors everywhere else
Is it possible that installing Devise 1.1.8 in a Rails 3.0.3 app, it somehow interferes with normal validations in non-devise models/controllers?
In my app, there's a User mo开发者_高级运维del tied to Devise. In addition, there's a Patient model with an attribute: mobile. (We collect the mobile number of patients for a healthcare app.)
class Patient < ActiveRecord::Base
#validates_presence_of :mobile, :message => "must be provided"
end
The above throws the following error:
You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.errors
-- and -- Extracted source (around line #12):
9: <h2><%= pluralize(@patient.errors.count, "error") %> prohibited this subscriber from being saved:</h2>
10:
11: <ul>
12: <% @subscriber.errors.full_messages.each do |msg| %>
13: <li><%= msg %></li>
14: <% end %>
15: </ul>
BTW, Devise works fine in displaying error messages when a new User makes an error (like not providing a password).
Also, removing :message => "must be provided" produces the exact same error.
Thanks.
@subscriber and @patient are different instance variables. You probably meant to use only one of them, and make sure it is actually initialized.
精彩评论