preferences_controller.rb 800 Bytes
Newer Older
1 2 3 4 5 6 7
class Profiles::PreferencesController < Profiles::ApplicationController
  before_action :user

  def show
  end

  def update
8 9 10 11 12 13 14 15 16
    begin
      if @user.update_attributes(preferences_params)
        flash[:notice] = 'Preferences saved.'
      else
        flash[:alert] = 'Failed to save preferences.'
      end
    rescue ArgumentError => e
      # Raised when `dashboard` is given an invalid value.
      flash[:alert] = "Failed to save preferences (#{e.message})."
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
    end

    respond_to do |format|
      format.html { redirect_to profile_preferences_path }
      format.js
    end
  end

  private

  def user
    @user = current_user
  end

  def preferences_params
32 33
    params.require(:user).permit(
      :color_scheme_id,
34
      :dashboard,
35
      :project_view,
36 37
      :theme_id
    )
38 39
  end
end