将名称添加到Spree Devise注册

我正在尝试添加姓名,姓氏和生日来设计Spree注册。

我已经安装了gem

gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '3-0-stable' 

创建了迁移:

  class AddFieldsToSpreeUsers < ActiveRecord::Migration def change add_column :spree_users, :name, :string add_column :spree_users, :surname, :string add_column :spree_users, :birthdate, :time end end 

创建了一个新表单来添加字段app / views / spree / shared / _user_form.html.erb

定义应用程序控制器中的方法以使用before操作运行

  class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception before_action :set_locale before_filter :configure_permitted_parameters, if: :devise_controller? def set_locale I18n.locale = params[:locale] || I18n.default_locale end protected def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:email, :password, :name, :surname, :birthdate) } devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:email, :password, :name, :surname, :birthdate) } end end 

我仍然没有在数据库中获得任何记录

  

以下是添加用户表单提交操作的控制台日志:

 Started POST "/signup" for ::1 at 2015-07-21 09:52:08 -0500 Processing by Spree::UserRegistrationsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"+9EoKHj9fkHqKF8TRtlcfIYt5+QPuPa1ynmWVifUNY3luiCDpiBP9z2VV/uMAH1JP0CCg7gwG2gu7vO1TaSacw==", "spree_user"=>{"name"=>"Christophe", "surname"=>"Mysurname", "email"=>"email@gmail.com", "password"=>"[FILTERED]", "birthdate"=>"1978-11-11"}, "commit"=>"Create"} Unpermitted parameters: name, surname, birthdate (0.6ms) BEGIN 

我究竟做错了什么? 我有未经许可的参数。

以下是基于以下post的答案:

Rails 4 – 强大的参数概念参与spree-2.1

我已经设法通过在config / initializers / spree.rb中添加以下行来添加名称,姓氏和生日

 Spree::PermittedAttributes.user_attributes.push :name, :surname, :birthdate 

我还通过以下迁移将birthdate从时间类型更改为日期类型:

 class ChangeBirthdateFromTimeToDate < ActiveRecord::Migration def up remove_column :spree_users, :birthdate, :time add_column :spree_users, :birthdate, :date end def down remove_column :spree_users, :birthdate, :date add_column :spree_users, :birthdate, :time end end 

你可以在终端运行命令:

 rails generate migration add_name_to_spree_users name:string rails generate migration add_sur_name_to_spree_users sur_name:string rails generate migration add_birthdate_to_spree_users birthdate:date rake db:migrate 

在inside config / initializers / spree.rb

Spree :: PermittedAttributes.user_attributes.push:name,:sur_name,:birthdate

比重启你的服务器