DougN
DougN

Reputation: 337

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 model 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.

Upvotes: 0

Views: 149

Answers (1)

eugen
eugen

Reputation: 9226

@subscriber and @patient are different instance variables. You probably meant to use only one of them, and make sure it is actually initialized.

Upvotes: 2

Related Questions