3

名前、姓、生年月日を追加して、Spree に登録しようとしています。

ジェムをインストールしました

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を追加する新しいフォームを作成しました

前のアクションで実行するアプリケーションコントローラーのメソッドを定義しました

   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

そして、私はまだデータベースにレコードを取得していません

<Spree::User id: 2, encrypted_password:   "bdd86072513f789da5a395080e3d16e28c96cfe5e3aaea105b...",
... , name: nil,  surname: nil, birthdate: nil> 

ユーザーフォームの追加送信アクションのコンソールログは次のとおりです。

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

私は何を間違っていますか?許可されていないパラメーターがあります。

4

2 に答える 2