我是 Ruby 编程新手,但登录后向导的第一步根本没有出现我的验证代码。我对两个额外字段的验证适用于初始屏幕,但其余字段不起作用有吗?
我也在使用 Devise gem 进行身份验证。
我试过实现这个代码点击这里!
我没有成功。我试图实现 user_id 但它也行不通。我添加了一个 puts 语句,我可以看到它被命中但没有发生验证?我试图做一些其他的事情,但没有运气。我不太明白这是横向的。请在下面查看我的代码。
我邪恶的步进控制器
class AfterRegistrationController < ApplicationController
include Wicked::Wizard
layout 'noheaderOrfooter', :only => [:new, :show, :create, :update]
#before_action :authenticate_user!
steps :addCompanyInfo, :taxInformation, :achBankInfo, :finalstep
def show
@user = current_user
render_wizard
end
def update
@user = current_user
params[:user][:current_step] = step
case wizard_value(step)
when :addCompanyInfo
@user.update_attributes(company_params)
when :taxInformation
@user.update_attributes(tax_params)
when :achBankInfo
@user.update_attributes(bank_params)
else
@user.update_attributes(final_params)
end
render_wizard @user
end
def company_params
params.require(:user).permit(:CompanyLegName, :CompnayWebsite, :CompanyAddrss, :CompSuitOrApt, :City, :State, :ZipCode, :current_step)
end
def tax_params
params.require(:user).permit(:EINbr, :startdate, :NbrOfTrucks, :estpayroll, :City, :State, :ZipCode)
end
def bank_params
params.require(:user).permit(:BankName, :RoutNbr, :AcctNbr, :confirmAcctNbr)
end
def final_params
params.require(:user).permit(:CompanyLegName, :CompnayWebsite, :CompanyAddrss, :CompSuitOrApt, :City, :State, :ZipCode)
end
end
设计注册控制器
def after_sign_up_path_for(resource)
after_registration_path(:addCompanyInfo)
end
用户模型
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
validates :fname, :lname, :presence => true
validates :CompanyLegName, :CompanyAddrss, :CompSuitOrApt, :City, :State, :ZipCode, :presence => true, if: -> { current_step?(:addCompanyInfo) }
def current_step?(step_key)
current_step == step_key
puts 'I hit this method'
puts step_key
end
# Setup accessible (or protected) attributes for your model
#attr_accessible :email, :password, :password_confirmation, :remember_me, :fname, :lname, #:CompanyLegName, :CompanyAddrss, :CompSuitOrApt, :City, :State, :ZipCode, :Ownersfname, #:OwnersLname
#devise :database_authenticatable, :registerable,
#:recoverable, :rememberable, :trackable, :validatable
end