1

I'm new to programming in Ruby but my code for validation is not occurring at all in the first step of my wizard after logging in. My validation for the two extra fields work for the initial screen but the remaining fields it doesn't work at all?

I'm using Devise gem for the authentication also.

I've tried implementing this code Click here!

I was not successful. I tried to implement user_id but it would also not work. I added a puts statement and i can see its being hit but no validation is occurring? I tried to do some other things with no luck. I don't quite understand where this is going sideways. Please see my code below.

My wicked step controller

    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

devise registration controller

def after_sign_up_path_for(resource)
after_registration_path(:addCompanyInfo)
end

user model

    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
skinnyWill
  • 327
  • 2
  • 18

1 Answers1

0

In my model i was comparing current_step which is a string to my step_key that was returning a parameter which would return false all the time i changed it to return a string which allowed me to compare current_step which is a string to step_key.to_s which is a string

below

 def current_step?(step_key)
   current_step == step_key.to_s 
 end
skinnyWill
  • 327
  • 2
  • 18