小编7su*_*ami的帖子

Rails 4&Devise - 创建新用户时,用户名不会添加到数据库中

我是Ruby on Rails环境的新手,也是我能够解决的大多数问题,但我还没有找到解决这个问题的方法.

提供上下文:

  • 使用rails(4.0.0)
  • 使用监狱长(1.2.3)
  • 使用设计(3.0.0)
  • 使用rolify(3.2.0)
  • 使用cancan(1.6.10)

我的问题

当我使用Devise的注册签署新用户时.:name字段未添加到数据库中.请参阅服务器输出

用户模型(app/models/user.rb)

:name包含在attr_accessible中.

class User < ActiveRecord::Base
  rolify
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :role_ids, :as => :admin
  attr_accessible :name, :email, :password, :password_confirmation, :remember_me

end
Run Code Online (Sandbox Code Playgroud)

用户控制器(app/controllers/users_controller.rb).

为了与Rails 4保持一致,我添加了params白名单,但这并没有解决问题.

class UsersController < ApplicationController
  before_filter :authenticate_user!

  def index
    authorize! :index, …
Run Code Online (Sandbox Code Playgroud)

authentication ruby-on-rails devise strong-parameters ruby-on-rails-4

5
推荐指数
2
解决办法
7455
查看次数