Class: Caboose::SettingsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Caboose::SettingsController
- Defined in:
- app/controllers/caboose/settings_controller.rb
Instance Method Summary collapse
- #before_action ⇒ Object
-
#create ⇒ Object
POST /admin/settings.
-
#destroy ⇒ Object
DELETE /admin/settings/1.
-
#edit ⇒ Object
GET /admin/settings/1/edit.
-
#index ⇒ Object
GET /admin/settings.
-
#new ⇒ Object
GET /admin/settings/new.
-
#options ⇒ Object
GET /admin/settings/options.
-
#update ⇒ Object
PUT /admin/settings/1.
Methods inherited from ApplicationController
#admin_add, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_delete, #admin_edit, #admin_index, #admin_json, #admin_json_single, #admin_update, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in
Instance Method Details
#before_action ⇒ Object
5 6 7 |
# File 'app/controllers/caboose/settings_controller.rb', line 5 def before_action @page = Page.page_with_uri(request.host_with_port, '/admin') end |
#create ⇒ Object
POST /admin/settings
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/caboose/settings_controller.rb', line 39 def create return if !user_is_allowed('settings', 'add') resp = StdClass.new({ 'error' => nil, 'redirect' => nil }) setting = Setting.new() setting.name = params[:name] setting.value = params[:value] if (setting.name.strip.length == 0) resp.error = "The setting name is required." else setting.save resp.redirect = "/admin/settings/#{setting.id}/edit" end render json: resp end |
#destroy ⇒ Object
DELETE /admin/settings/1
80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/caboose/settings_controller.rb', line 80 def destroy return if !user_is_allowed('settings', 'delete') setting = Setting.find(params[:id]) setting.destroy resp = StdClass.new({ 'redirect' => '/admin/settings' }) render json: resp end |
#edit ⇒ Object
GET /admin/settings/1/edit
33 34 35 36 |
# File 'app/controllers/caboose/settings_controller.rb', line 33 def edit return if !user_is_allowed('settings', 'edit') @setting = Setting.find(params[:id]) end |
#index ⇒ Object
GET /admin/settings
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/caboose/settings_controller.rb', line 10 def index return if !user_is_allowed('settings', 'view') @gen = PageBarGenerator.new(params, { 'name' => nil, 'value' => nil },{ 'model' => 'Caboose::Setting', 'sort' => 'name', 'desc' => false, 'base_url' => '/admin/settings', 'use_url_params' => false }) @settings = @gen.items end |
#new ⇒ Object
GET /admin/settings/new
27 28 29 30 |
# File 'app/controllers/caboose/settings_controller.rb', line 27 def new return if !user_is_allowed('settings', 'add') @setting = Setting.new end |
#options ⇒ Object
GET /admin/settings/options
92 93 94 95 96 97 |
# File 'app/controllers/caboose/settings_controller.rb', line 92 def return if !user_is_allowed('settings', 'view') settings = Setting.reorder('name').all = settings.collect { |s| { 'value' => s.id, 'text' => s.name }} render json: end |
#update ⇒ Object
PUT /admin/settings/1
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/caboose/settings_controller.rb', line 61 def update return if !user_is_allowed('settings', 'edit') resp = StdClass.new setting = Setting.find(params[:id]) save = true params.each do |name,value| case name when "name" then setting.name = value when "value" then setting.value = value end end resp.success = save && setting.save render :json => resp end |