1

我是 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
4

1 回答 1

0

在我的模型中,我正在比较 current_step 这是一个字符串,我的 step_key 返回一个参数,该参数将在我更改它以返回一个字符串时返回一个允许我比较 current_step 这是一个字符串 step_key.to_s 这是一个细绳

以下

 def current_step?(step_key)
   current_step == step_key.to_s 
 end
于 2019-05-04T00:47:34.730 回答