class ProfileController

Public Instance Methods

edit() click to toggle source

To edit profile steps

# File app/controllers/profile_controller.rb, line 8
def edit
  @user = current_user
  @user.profile_step = User::PROFILE_STEPS.call.rindex(step)
  build_nested_objects
  if step.present?
    render "profile/steps/#{User.profile_step_partial(step)}"
  else
    render "#{Rails.root.to_s}/public/404.html", :layout => false, :status => 404
  end
end
show() click to toggle source

To visit user profile.

# File app/controllers/profile_controller.rb, line 47
def show
  @user = User.find_by_id(params[:id])
  if @user
    add_breadcrumb "Dashboard", :dashboard_path  if logged_in?
    add_breadcrumb "Search Results", :tutors_path
    add_breadcrumb @user.name, :profile_path
    ProfileVisit.increment!(@user, current_user)
    @reviews = @user.recieved_reviews.order('average_review DESC').page(1).per(3) if @user.tutor?
    render layout: 'application'
  else
    flash[:notice] = 'That user does not exist'
    redirect_to root_url
  end
end
update() click to toggle source

To update profile steps

# File app/controllers/profile_controller.rb, line 20
def update
  @user = current_user
  respond_to do |format|
    if @user.update_attributes(user_params)
      if next_step
        format.html { redirect_to edit_profile_path(next_step) }
        format.js { redirect_via_turbolinks_to edit_profile_path(next_step)}
      else
        message = current_user.update_columns(is_registration_completed: true) if current_user.student?
          unless @user.is_registration_completed?
            'Your profile is now complete, you will be visible to students once your profile is approved. You will receive an email shortly.'
          else
            'Your profile is updated'
          end
        redirect_path = dashboard_path
        format.html { redirect_to redirect_path, notice: message}
        format.js { redirect_via_turbolinks_to redirect_path, notice: message}
        UserMailer.delay(queue: :mailer).profile_completion(@user)
      end
    else
      format.html {redirect_to "profile/steps/#{User.profile_step_partial(step)}"}
      format.js { render template: "profile/steps/#{User.profile_step_partial(step)}", object: @user, within: '#profile_steps_content'}
    end
  end
end