用于设计动作控制器复制数据的表单

时间:2018-03-19 11:13:23

标签: ruby-on-rails devise elm

我使用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正在工作,因为它应该工作,创建动作正在接收正确的数据。有人有线索吗?

0 个答案:

没有答案