Class: Settr::SettingsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Settr::SettingsController
- Defined in:
- app/controllers/settr/settings_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #settings ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/settr/settings_controller.rb', line 8 def create @setting = SettrSetting.new(params[:settr_setting]) if @setting.select? unless @setting..include?(@setting.value) flash[:error] = t('settr.setting.not_created_value_not_in_options') redirect_to settr_settings_path return end end if @setting.save flash[:success] = t('settr.setting.created') else flash[:error] = t('settr.setting.not_created') end redirect_to settr_settings_path end |
#destroy ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/settr/settings_controller.rb', line 54 def destroy @setting = SettrSetting.find(params[:id]) if @setting.destroy flash[:success] = t('settr.setting.deleted') else flash[:error] = t('settr.setting.not_deleted') end redirect_to settr_settings_path end |
#edit ⇒ Object
27 28 29 |
# File 'app/controllers/settr/settings_controller.rb', line 27 def edit @setting = SettrSetting.find(params[:id]) end |
#index ⇒ Object
50 51 52 |
# File 'app/controllers/settr/settings_controller.rb', line 50 def index @settings = SettrSetting.order(:key) end |
#new ⇒ Object
4 5 6 |
# File 'app/controllers/settr/settings_controller.rb', line 4 def new @setting = SettrSetting.new end |
#settings ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/settr/settings_controller.rb', line 64 def settings @settings = Settr.alterable if request.post? params[:settr].each do |k, v| setting = SettrSetting.find_by_key(k) setting.value = (setting.typ == 'boolean' ? (v == '1').to_s : v) setting.save! end flash[:success] = t('settr.settings.saved') redirect_to settings_settr_settings_path end end |
#update ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/settr/settings_controller.rb', line 31 def update @setting = SettrSetting.find(params[:id]) @new_setting = SettrSetting.new(params[:settr_setting]) if @new_setting.select? unless @new_setting..include?(@setting.value) flash[:error] = t('settr.setting.not_updated_value_not_in_options') redirect_to settr_settings_path return end end if @setting.update_attributes(params[:settr_setting]) flash[:success] = t('settr.setting.updated') else flash[:error] = t('settr.setting.not_updated') end redirect_to settr_settings_path end |