我使用devise-4.4.1
{el} rails-5.1.4
上的0.18
来构建注册表单,将数据发布到此处定义的经典/users.json
操作:< / p>
devise_for :users, controllers: { registrations: 'users/registrations' }
榆树形式也很常见,我使用etaque/elm-form并序列化为JSON:
case formMsg of
Form.Submit ->
case user_ of
Just user_ ->
let
request = Http.post "/users.json" (Http.jsonBody (user userDecode
in
( model , Http.send PostUser request )
Nothing ->
({ model | form = form_ }, Cmd.none)
这很有效,这是Json我按照浏览器接收&#34;复制POST数据&#34;
{
"user": {
"type":"designer",
"role":"designer",
"first_name":"dsfdsfsd",
"last_name":"dsdsfds",
"email":"dfsddfs@kdsfjfgkd",
"password":"fdsfdfsdfds"
}
}
但不幸的是,这是params.inspect
在Devise Registration控制器中告诉我的内容:
Processing by Users::RegistrationsController#create as JSON
11:02:06 web.1 | Parameters: {"user"=>{"type"=>"designer", "role"=>"designer", "first_name"=>"sdadas", "last_name"=>"asdasda", "email"=>"sadasad@fsdfd", "password"=>"[FILTERED]"}, "registration"=>{"user"=>{"type"=>"designer", "role"=>"designer", "first_name"=>"sdadas", "last_name"=>"asdasda", "email"=>"sadasad@fsdfd", "password"=>"[FILTERED]"}}}
正如您所看到的数据看起来重复,我有一个user
哈希和一个registration[user]
哈希。
这是控制器代码:
class Users::RegistrationsController < Devise::RegistrationsController
before_action :configure_sign_up_params, only: [:create]
def create
puts params.inspect
super
end
def configure_sign_up_params
devise_parameter_sanitizer.permit(:sign_up, keys: [:type, :role, :first_name, :last_name])
end
end
我的问题是:Devise在做什么以及为什么?我在这里错过了什么吗?看起来Elm正在工作,因为它应该工作,创建动作正在接收正确的数据。有人有线索吗?