2012-07-26 42 views
2

每当我打出了牌子的按钮,我得到以下错误:设计未定义的方法`电子邮件”

NoMethodError in Devise/sessions#new 

Showing /Users/chanel.n/svn- work/gwb/trunk/PMOCCU/ProcessEnforcer/app/views/devise/sessions/new.html.erb where line #5 raised: 

undefined method `email' for #<User id: nil, name: nil, created_at: nil, updated_at: nil> 
Extracted source (around line #5): 

2: 
3: <%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %> 
4: <div class="field"><%= f.label :email %><br /> 
5: <%= f.email_field :email %></div> 
6: 
7: <div class="field"><%= f.label :password %><br /> 
8: <%= f.password_field :password %></div> 
Rails.root: /Users/chanel.n/svn-work/gwb/trunk/PMOCCU/ProcessEnforcer 

Application Trace | Framework Trace | Full Trace 
app/views/devise/sessions/new.html.erb:5:in `block in _app_views_devise_sessions_new_html_erb___4179931318693150703_70215900182100' 
app/views/devise/sessions/new.html.erb:3:in `_app_views_devise_sessions_new_html_erb___4179931318693150703_70215900182100' 

这里是我的用户模型,其中包括电子邮件:

class User < Role 
has_and_belongs_to_many :roles 

attr_accessible :name, :roles 

# Include default devise modules. Others available are: 
# :token_authenticatable, :confirmable, 
# :lockable, :timeoutable and :omniauthable 
devise :database_authenticatable, :registerable, 
    :lockable, :timeoutable, :trackable, :validatable, :token_authenticatable 

# Setup accessible (or protected) attributes for your model 
attr_protected :email, :password, :password_confirmation, :department, :encrypted_password 
# attr_accessible :title, :body, :remember_me 

validates_presence_of :email 

end 

无论出于何种原因,它不承认电子邮件。

有没有其他人遇到过这个问题?

回答

0

您的电子邮件字段是不是在用户模式访问,你应该让访问使用:

attr_accessible :name, :roles, :email 
+0

非常感谢。这工作。 – 2012-07-26 22:22:59

0

设计默认使用电子邮件作为登录,因此它需要你有:email和:encrypted_pa​​ssword字段。

您的User模型中没有任何一个。所以,你需要添加这些字段。

+0

我的用户模型中确实有电子邮件。 – 2012-07-26 20:18:20

+0

我在上面添加了用户模型。 – 2012-07-26 20:22:35

0

其他建议并没有在我的案件有关。我的设计版本过时了。升级到3.2.4为我解决了它。

主要的问题是看起来,设计产生的迁移在新版本中是不同的。

相关问题