Class: SettingsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/settings_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



5
6
# File 'app/controllers/settings_controller.rb', line 5

def index
end

#update_allObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/settings_controller.rb', line 8

def update_all
  success = false

  #If no section selected, skips and gives error
  if params[:settings_section].present?
    section = params[:settings_section].to_s

    #Updating notifications settings
    if section.eql? "notifications"
      #Notify by email setting
      if params[:notify_by_email].present?
        notify_by_email = params[:notify_by_email].to_s
        current_subject.notify_by_email = false if notify_by_email.eql? "never"
        current_subject.notify_by_email = true if notify_by_email.eql? "always"
      end

      # Custom notification settings
      if params[:notification_settings].present?
        notification_settings = {}
        params[:notification_settings].each_pair do |key, setting|
          notification_settings[key.to_sym] = false if setting.eql? "never"
          notification_settings[key.to_sym] = true if setting.eql? "always"
        end
        current_subject.update_attribute(:notification_settings, notification_settings)
      end
    end

    #Updating language
    if section.eql? "language"
      #Preferred language setting
      if params[:language].present?
        lang = params[:language].to_s
        if lang == 'browser'
          current_user.language = nil
        else
          current_user.language = lang[0..1]
        end
      end
    end

    #Here sections to add
    #if section.eql? "section_name"
    #   blah blah blah
    #end

    # Was everything ok?
    success = current_subject.save && current_user.save
  end

  #Flashing and redirecting
  if success
    flash[:success] = t('settings.success')
  else
    flash[:error] = t('settings.error')
  end
  # render :action => :index

  redirect_to settings_path
end