如何修复邪恶向导第一步中未发生的“验证”

时间:2019-05-03 02:00:25

标签: ruby-on-rails ruby-on-rails-5 wicked-gem

我是Ruby编程的新手,但登录后在向导的第一步中根本没有进行验证的代码。我对两个额外字段的验证适用于初始屏幕,但其余字段却不起作用根本不工作吗?

我也在使用Devise gem进行身份验证。

我已尝试实现此代码单击here

我没有成功。 我尝试实现user_id,但也无法正常工作。 我添加了一个看跌期权声明,可以看到它被击中了,但是 没有验证? 我尝试做其他的事时没有运气。我不太 了解这是横向的。  请在下面查看我的代码。

我邪恶的脚步控制器

    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

1 个答案:

答案 0 :(得分:0)

在我的模型中,我正在比较current_step(它是一个字符串)与我的step_key(它返回一个参数),该参数在我更改它的所有时间都会返回false,以返回一个字符串,这使我可以将current_step(它是一个字符串)与step_key.to_s比较这是一个字符串

下方

fcntl(F_SETFL, O_NONBLOCK)