我将邪恶的宝石用于步骤(向导)的候选个人资料构建,并使用 Devise 进行授权。
候选人首先需要使用最少的信息(名称,电子邮件,密码等)进行注册,然后在注册之后,将用户重定向到ProfileBuild的第一个用户(在这种情况下为:education)。每个步骤都经过独立验证,但是我不知道如何首先验证设备注册,然后再验证其他步骤。
class Candidate < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
has_one :educational_institution
has_and_belongs_to_many :areas
has_many :skills
has_many :links
has_many :work_experiences
cattr_accessor :form_steps do
%w(education job_preferences employment_preferences work_experiences final_facts)
end
attr_accessor :current_step
validates :graduation_date, presence: true, if: -> { current_step?(:education) }
def current_step?(step)
current_step.blank? || current_step == step
end
end
向导控制器:
class ProfileBuildController < ApplicationController
include Wicked::Wizard
before_action :set_candidate, only: [:show, :update]
steps *Candidate.form_steps
def show
render_step(params[:id])
end
def update
@candidate.update(candidate_params(step))
render_wizard @candidate
end
private
def redirect_to_finish_wizard(options = nil)
redirect_to root_url, notice: "Thank you for signing up."
end
def set_candidate
@candidate = current_candidate
end
def candidate_params(step)
permitted_attributes = case step
when "education"
[:graduation_date, :academic_degree_name]
when "job_preferences"
[:job_preferences, :available_start_date]
when "employment_preferences"
[:employment_preferences]
end
params.require(:candidate).permit(permitted_attributes).merge(current_step: step)
end
end