为什么Devise一直问我这个名字不能是空白的?

我是Rails的新手,我正在与Devise合作。 我面临的问题是我的表单在注册时没有更新用户的名称列。 我在数据表中有name属性,但我似乎无法使用设计注册中的表单来更改它。

Sign up

resource_name, :url => registration_path(resource_name)) do |f| %>

true %>



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

Scheme.rb

 ActiveRecord::Schema.define(version: 20130622203624) do create_table "posts", force: true do |t| t.integer "user_id" t.text "description" t.integer "comments_id" t.datetime "created_at" t.datetime "updated_at" t.string "title" end create_table "users", force: true do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.integer "sign_in_count", default: 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.datetime "created_at" t.datetime "updated_at" t.string "name", null: false end add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree create_table "views", force: true do |t| t.string "email", default: "", null: false t.string "encrypted_password", limit: 128, default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.integer "sign_in_count", default: 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.datetime "created_at" t.datetime "updated_at" end add_index "views", ["email"], name: "index_views_on_email", unique: true, using: :btree add_index "views", ["reset_password_token"], name: "index_views_on_reset_password_token", unique: true, using: :btree end 

如果您使用的是rails4,则需要强大的参数。 如果你需要实现额外的参数来设计,你可以为用户创建一个额外的1-1关系称为配置文件并将它们存储在那里(从长远来看应用程序或者如果你有更多的用户数据更好)我个人觉得它将您的用户数据合并到设计用户表中要容易得多。

或者,如果您使用一个或两个属性,则可以执行以下操作。

您需要为设计允许name参数。 在您的ApplicationController代码中,执行此操作。

 class ApplicationController < ActionController::Base before_filter :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_up) << :name end end 

在设计维基上详细介绍。

需要进行以下更改 – 这应该修复它

gem’protected_attributes’

class RegistrationsController

def configure_permitted_pa​​rameters devise_parameter_sanitizer.for(:sign_up)do | u | u.permit(:name,:user_type,:email,:password,:password_confirmation)结束

devise_parameter_sanitizer.for(:account_update)do | u | u.permit(:name,:user_type,:email,:password,:password_confirmation,:current_password)end end