Sha256: 99e908fc476c827fa30d74e38d0fbee9698a5b8d9d954dce771bf2a3520bfa33

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

class Kiqr::OnboardingController < KiqrController
  skip_before_action :ensure_onboarded
  before_action :setup_user

  before_action do
    # This is to prevent users from accessing the onboarding process
    # if they have already completed it. A user can only have one
    # personal account. If they have one, they have completed the
    # onboarding process.
    redirect_to dashboard_path if current_user.onboarded?

    # This is to set the breadcrumbs for the onboarding process.
    add_breadcrumb I18n.t("kiqr.breadcrumbs.onboarding"), onboarding_path
  end

  def show
    @user.build_personal_account(personal: true)
  end

  def update
    @user.assign_attributes(user_params)
    @user.personal_account.personal = true

    if @user.save
      kiqr_flash_message(:notice, :onboarding_completed)
      redirect_to after_onboarding_path(@user)
    else
      render :show, status: :unprocessable_entity
    end
  end

  private

  def setup_user
    @user = User.find(current_user.id)
  end

  def user_params
    account_attributes = Kiqr.config.account_attributes.prepend(:id)
    params.require(:user).permit(:time_zone, :locale, personal_account_attributes: account_attributes)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kiqr-0.1.0.alpha1 app/controllers/kiqr/onboarding_controller.rb