Злой с разработкой и проверкой на родство - PullRequest
0 голосов
/ 05 апреля 2019

Я использую Wicked gem для пошагового построения профиля кандидата (мастер) и Devise для авторизации.

Кандидату сначала необходимо зарегистрироваться с минимальным количеством информации (имя, адрес электронной почты, пароль и т. Д.), Затем после регистрации пользователь перенаправляется на первую страницу ProfileBuild (в данном случае: образование). Каждый шаг проверяется независимо, но я не знаю, как сначала проверить правильность регистрации, а затем другие шаги.

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
...