Ruby on rails 巫术用户注册错误,属性密码无效\u确认
我不断收到错误信息,表示属性密码无效\u确认。我不知道我做错了什么。有人能解释一下需要在sorcery用户控制器中传递哪些安全参数来创建用户吗 我不断收到错误Ruby on rails 巫术用户注册错误,属性密码无效\u确认,ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,我不断收到错误信息,表示属性密码无效\u确认。我不知道我做错了什么。有人能解释一下需要在sorcery用户控制器中传递哪些安全参数来创建用户吗 我不断收到错误 Failures: 1) Users can sign Up With Valid attributes Failure/Error: @user = User.new(user_params) ActiveRecord::UnknownAttributeError: unknown attrib
Failures:
1) Users can sign Up With Valid attributes
Failure/Error: @user = User.new(user_params)
ActiveRecord::UnknownAttributeError:
unknown attribute 'password_confirmation' for User.
# ./app/controllers/users_controller.rb:8:in `create'
# ./spec/feature/sign_up_spec.rb:27:in `block (2 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# NoMethodError:
# undefined method `password_confirmation=' for #<User:0x00563958734578>
# ./app/controllers/users_controller.rb:8:in `create'
class UsersController < ApplicationController
layout 'static_application'
def new
@user = User.new
end
def create
@user = User.new(user_params)
if @user.save
flash[:notice] = 'Thank you for Applying for PetroHub account. We are currently reviewing your application, which might take upto 24hrs.'
redirect_to user_thankyou_path(@user)
else
flash[:alert] = 'Oops! something went wrong. Please check your application and resubmit. Thank you.'
end
end
def thank_you
@user = User.find(params[:id])
end
private
def user_params
params.require(:user).permit(:first_name,:last_name,:business_name,:phone_number,:cell_number,:street_address,:apt_suite,:city,:state,:zip_code,:tax_id,:ssn,:in_biz,:terms,:email,:password,:password_confirmation)
end
end
向您的模型添加
验证密码的确认。这将在模型对象中创建属性
但是,请注意,这使得所有对模型对象密码的编辑都需要确认,包括在Rails控制台中。最好在您的控制器或服务对象中强制执行确认。我没有使用巫术,但我认为您的模型可能缺少验证:密码的确认。
。这将在模型上创建一个访问器,用于确认密码。令人惊叹的!就这样。
require 'rails_helper'
RSpec.feature 'Users can sign Up' do
scenario 'With Valid attributes' do
visit '/'
click_link 'apply'
expect(page.current_url).to eq signup_url
fill_in 'First Name', with: 'John'
fill_in 'Last Name', with: 'Doe'
fill_in 'Business Name', with: 'Acme Inc'
fill_in 'Phone Number', with: '2124567890'
fill_in 'Cell Number', with: '5202124567'
fill_in 'Street Address', with: '212 Wise St'
fill_in 'Apt/Suite', with: '410'
fill_in 'City', with: 'New york'
select "New York", :from => "State"
fill_in 'Zip Code', with: '11104'
fill_in 'Tax ID', with: '12345678'
fill_in 'SSN', with: '124000987'
fill_in 'How many years in Business?', with: '5'
fill_in 'Email', with: 'test@example.com'
fill_in 'user_password', with: 'password'
fill_in 'user_password_confirmation', with: 'password'
check('user_terms')
click_button 'Apply'
expect(page).to have_content 'Thank you for Applying for PetroHub account. We are currently reviewing your application, which might take upto 24hrs.'
end
scenario 'With Invalid attributes' do
end
end