Class: Character::SettingsController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Character::SettingsController
- Includes:
- AuthConcern, InstanceConcern
- Defined in:
- app/controllers/character/settings_controller.rb
Overview
Author: Alexander Kravets
Slate, 2013
Instance Method Summary collapse
Instance Method Details
#set_template_name ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/character/settings_controller.rb', line 12 def set_template_name @action_url = "/#{ character_instance.name }/settings/#{ params[:template_name] }" @instance_template = "/#{ character_instance.name }/settings/#{ params[:template_name] }" @character_template = "/character/settings/#{ params[:template_name] }" @generic_template = "character/settings/settings_group" if template_exists?(@instance_template) @template = @instance_template elsif template_exists?(@character_template) @template = @character_template else @settings_group_name = params[:template_name].gsub('_', ' ').titleize @template = @generic_template end end |
#show ⇒ Object
29 30 31 |
# File 'app/controllers/character/settings_controller.rb', line 29 def show render @template end |
#update ⇒ Object
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 |
# File 'app/controllers/character/settings_controller.rb', line 33 def update @objects = [] class_name = params[:class_name] model_class = class_name.constantize if not params[:objects].nil? params[:objects].first.each_pair do |id_or_slug, attributes| if attributes.size > 0 begin object = model_class.find id_or_slug rescue Mongoid::Errors::DocumentNotFound object = model_class.new end if attributes[:_destroy] == 'true' object.destroy else object.update_attributes(attributes) @objects << object end end end # Hack: this helps to save new objects using unique ids @objects.each do |o| o.new_record = false if o.new_record end end render @template end |