Ruby on rails 轨道控制器/装置见空参数

Ruby on rails 轨道控制器/装置见空参数,ruby-on-rails,ruby,rspec,devise,Ruby On Rails,Ruby,Rspec,Devise,我已经创建了一个表单,用户可以注册我的应用程序,只需稍加调整,就可以同时加入他们的公司名称。但是,我的rspec测试和手动测试表明,没有通过参数来创建用户/公司 最后,我需要能够创建一个用户,还需要创建一个公司,目前只使用公司名称 以下是注册表格的视觉效果: 注册管理员: 特性测试结果: 我在网上看过各种帖子,试图弄明白这一点,并假设这与我在用户表单中嵌套的company属性有关,但仍然无法解开这个谜团。我认为设计注册控制器创建操作没有使用强参数,也没有得到输入 他们出现在请求中 "user"

我已经创建了一个表单,用户可以注册我的应用程序,只需稍加调整,就可以同时加入他们的公司名称。但是,我的rspec测试和手动测试表明,没有通过参数来创建用户/公司

最后,我需要能够创建一个
用户
,还需要创建一个
公司
,目前只使用公司名称

以下是注册表格的视觉效果:

注册管理员:

特性测试结果:


我在网上看过各种帖子,试图弄明白这一点,并假设这与我在用户表单中嵌套的
company
属性有关,但仍然无法解开这个谜团。

我认为设计注册控制器创建操作没有使用强参数,也没有得到输入

他们出现在请求中

"user"=>{"company_attributes"=>{"name"=>"Test Company"}, "name"=>"Test User", "email"=>"test@test.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
但它们可能不被允许作为强参数,事实上,如果你阅读你的查询,它是用
email=“
一个空白字符串来完成的。没有参数被清除

WHERE "users"."email" = $1 LIMIT $2  [["email", ""], ["LIMIT", 1]]
website_1   | [9493b284-c9dc-4832-9be9-e876feb621f4]    (2.0ms)  ROLLBACK
也许你的消毒方法写错了?也许你可以这样尝试,甚至把他包括在应用程序控制器中

def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:email, :name, company_attributes: [:name]])
end 
此外,我没有在我的强参数中包含designe的
:password
,我读到它不安全,但现在我不确定。尽管我对标准装置的理解已经适用于
:password
:password\u confirmation
,但在创建新操作时,您可能需要所有参数

另外,新操作可能正在控制器中使用强参数,但来自此控制器的创建操作仍在使用它们自己的强参数


日志中的错误表明您已经有一个用户使用该电子邮件。尝试不同的电子邮件和电子邮件check@Pavan我认为这是一个要回滚的design std错误消息。用户是由电子邮件地址创建的,并且由于某种原因没有传递电子邮件。我在手动尝试时看到的实际HTML输出在功能测试中更为相关。@Pavan在该查询中选择电子邮件等于空白字符串的用户,其中“用户”。“email”=$1限制$2[[“email”,“]”,,而在对
/users
的HTTP post请求中,他在参数
user[:email]中实际拥有 = test@test.com
因此,我希望看到控制器操作,因为这是Desive。我不认为您确实更改了创建操作,也许您应该调试创建操作以了解请求的错误。因此,您基本上认为我正在处理此问题,因为
键:
缺失?我将给出
配置当我回到办公室时,我允许对参数进行这个小小的更改。请注意,你似乎无法更改Deavise使用的方法名称。我最初有
注册参数
,但一旦我按照建议将其更改回Deavise默认值,它就起作用了!@Godzilla74太好了!是的,这不是很容易。Deavise是复杂。我很高兴这对你有帮助。谢谢
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>

   <%= f.fields_for :company do |company_form| %>
       <%= company_form.text_field :name, class: 'form-control', autofocus: true, placeholder: 'ACME Inc.' %>
   <% end %>

   <%= f.text_field :name, class: 'form-control', placeholder: 'John Doe' %>

   <%= f.text_field :email, class: 'form-control', placeholder: 'john.doe@company.com' %>

   <%= f.password_field :password, class: 'form-control', autocomplete: 'off', placeholder: 'Password' %>

   <%= f.password_field :password_confirmation, class: 'form-control', autocomplete: 'off', placeholder: 'Password Confirmation' %>

   <%= f.submit 'Sign up', class: 'btn btn-primary btn-block btn-flat' %>

<% end %>
require 'rails_helper'

RSpec.feature "User Registration", :type => :feature do
  scenario "A new user is created" do
    # this will cover the user profile signup info
    visit "/users/sign_up"
    fill_in "user_company_attributes_name", with: "ACME Inc."
    fill_in "user_name", with: "Bob Jones"
    fill_in "user_email", with: "bob@jones.com"
    fill_in "user_password", with: "password"
    fill_in "user_password_confirmation", with: "password"
    click_button "Sign up"
    expect(page).to have_text("You have signed up successfully")
  end
end
Failures:

  1) User Registration A new user is created
     Failure/Error: expect(page).to have_text("You have signed up successfully")
       expected to find text "You have signed up successfully" in "x 4 errors prohibited this user from being saved: Email can't be blankPassword can't be blankName can't be blankCompany must exist NeoUI Sign up to start getting secure can't be blank can't be blank can't be blank"
     # ./spec/features/user_registration_spec.rb:25:in `block (2 levels) in <top (required)>'
website_1   | [9493b284-c9dc-4832-9be9-e876feb621f4] Started POST "/users" for 172.19.0.1 at 2017-06-29 11:37:30 +0000
website_1   | [9493b284-c9dc-4832-9be9-e876feb621f4] Cannot render console from 172.19.0.1! Allowed networks: 172.23.0.0/172.23.0.255, 127.0.0.0/127.255.255.255, ::1
website_1   | [9493b284-c9dc-4832-9be9-e876feb621f4] Processing by Users::RegistrationsController#create as HTML
website_1   | [9493b284-c9dc-4832-9be9-e876feb621f4]   Parameters: {"utf8"=>"✓", "authenticity_token"=>"HiqRhDZ4hddR65vZ+EVPP3dezr3yemz5HuU0gy4Wo/Tt7xtpm00F8JG6kNdMjPWQiGrPOu9xk0FfF1HjtFaqiQ==", "user"=>{"company_attributes"=>{"name"=>"Test Company"}, "name"=>"Test User", "email"=>"test@test.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
website_1   | [9493b284-c9dc-4832-9be9-e876feb621f4]    (3.2ms)  BEGIN
website_1   | [9493b284-c9dc-4832-9be9-e876feb621f4]   User Exists (1.9ms)  SELECT  1 AS one FROM "users" WHERE "users"."email" = $1 LIMIT $2  [["email", ""], ["LIMIT", 1]]
website_1   | [9493b284-c9dc-4832-9be9-e876feb621f4]    (2.0ms)  ROLLBACK
website_1   | [9493b284-c9dc-4832-9be9-e876feb621f4]   Rendering /usr/local/bundle/gems/devise-4.3.0views/devise/registrations/new.html.erb within layouts/signup
website_1   | [9493b284-c9dc-4832-9be9-e876feb621f4]   Rendered /usr/local/bundle/gems/devise-4.3.0views/devise/shared/_links.html.erb (4.1ms) [cache miss]
website_1   | [9493b284-c9dc-4832-9be9-e876feb621f4]   Rendered /usr/local/bundle/gems/devise-4.3.0views/devise/registrations/new.html.erb within layouts/signup (35.3ms)
website_1   | [9493b284-c9dc-4832-9be9-e876feb621f4] Completed 200 OK in 814ms (Views: 705.5ms | ActiveRecord: 7.1ms)
"user"=>{"company_attributes"=>{"name"=>"Test Company"}, "name"=>"Test User", "email"=>"test@test.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
WHERE "users"."email" = $1 LIMIT $2  [["email", ""], ["LIMIT", 1]]
website_1   | [9493b284-c9dc-4832-9be9-e876feb621f4]    (2.0ms)  ROLLBACK
def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:email, :name, company_attributes: [:name]])
end