我已添加名稱,姓氏和出生日期字段來設計註冊。 這裏是我原來的問題的鏈接。自定義Spree設計註冊 - 管理員授權失敗
Adding name to Spree Devise registration
看來,在前端側一切正常。但是,當我嘗試訪問我的管理員時,我現在收到授權失敗警報。
這裏是控制檯日誌:
Started GET "/admin/orders" for ::1 at 2015-07-21 13:25:16 -0500
Processing by Spree::Admin::OrdersController#index as HTML
Spree::Preference Load (0.3ms) SELECT "spree_preferences".* FROM "spree_preferences" WHERE "spree_preferences"."key" = $1 LIMIT 1 [["key", "spree/backend_configuration/locale"]]
Spree::User Load (0.5ms) SELECT "spree_users".* FROM "spree_users" WHERE "spree_users"."deleted_at" IS NULL AND "spree_users"."id" = $1 ORDER BY "spree_users"."id" ASC LIMIT 1 [["id", 6]]
(0.7ms) SELECT COUNT(*) FROM "spree_roles" INNER JOIN "spree_roles_users" ON "spree_roles"."id" = "spree_roles_users"."role_id" WHERE "spree_roles_users"."user_id" = $1 AND "spree_roles"."name" = $2 [["user_id", 6], ["name", "admin"]]
Redirected to http://localhost:3000/unauthorized
Completed 302 Found in 88ms (ActiveRecord: 4.1ms)
我試圖重寫應用程序/控制器/大禮包/管理/ users_controller_decorator.rb
module Spree
module Admin
UsersController.class_eval do
private
def user_params
params.require(:user).permit(:email, :password, :password_confirmation, :spree_role_ids, :name, :surname, :birthdate)
end
end
end
end
我認爲,如果你已經添加在用戶這三個領域在配置允許的屬性,你不不必重寫用戶控制器,因爲它已經使用allowed_user_attributes。 – Moh
是的,但對於像名稱等附加領域,他已經覆蓋用戶控制器或任何在初始化器中的位置,她已允許其他文件,如 Spree :: PermittedAttributes.user_attributes <<:名稱 – shoaib