Module: Brightcontent::BaseControllerExt::DefaultActions
- Extended by:
- ActiveSupport::Concern
- Included in:
- Brightcontent::BaseController
- Defined in:
- lib/brightcontent/base_controller_ext/default_actions.rb
Instance Method Summary collapse
- #base_collection ⇒ Object
- #collection ⇒ Object
- #collection=(val) ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #resource ⇒ Object
- #resource=(val) ⇒ Object
- #resource_class ⇒ Object
- #resource_collection_name ⇒ Object
- #resource_human_name(options = {}) ⇒ Object
- #resource_instance_name ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#base_collection ⇒ Object
14 15 16 |
# File 'lib/brightcontent/base_controller_ext/default_actions.rb', line 14 def base_collection instance_variable_get :"@#{resource_collection_name}" end |
#collection ⇒ Object
18 19 20 |
# File 'lib/brightcontent/base_controller_ext/default_actions.rb', line 18 def collection base_collection end |
#collection=(val) ⇒ Object
22 23 24 |
# File 'lib/brightcontent/base_controller_ext/default_actions.rb', line 22 def collection=(val) instance_variable_set :"@#{resource_collection_name}", val end |
#create ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/brightcontent/base_controller_ext/default_actions.rb', line 64 def create self.resource = base_collection.new(resource_params) if resource.save redirect_to resource_redirect_path, notice: t("flash.actions.create.notice", resource_name: resource_human_name) else render :new end end |
#destroy ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/brightcontent/base_controller_ext/default_actions.rb', line 81 def destroy if resource.destroy redirect_to resource_index_path, notice: t("flash.actions.destroy.notice", resource_name: resource_human_name) else redirect_to resource_index_path, alert: t("flash.actions.destroy.alert", resource_name: resource_human_name) end end |
#edit ⇒ Object
61 62 |
# File 'lib/brightcontent/base_controller_ext/default_actions.rb', line 61 def edit end |
#index ⇒ Object
50 51 |
# File 'lib/brightcontent/base_controller_ext/default_actions.rb', line 50 def index end |
#new ⇒ Object
57 58 59 |
# File 'lib/brightcontent/base_controller_ext/default_actions.rb', line 57 def new self.resource = base_collection.new end |
#resource ⇒ Object
26 27 28 |
# File 'lib/brightcontent/base_controller_ext/default_actions.rb', line 26 def resource instance_variable_get :"@#{resource_instance_name}" end |
#resource=(val) ⇒ Object
30 31 32 |
# File 'lib/brightcontent/base_controller_ext/default_actions.rb', line 30 def resource=(val) instance_variable_set :"@#{resource_instance_name}", val end |
#resource_class ⇒ Object
34 35 36 |
# File 'lib/brightcontent/base_controller_ext/default_actions.rb', line 34 def resource_class controller_name.classify.constantize end |
#resource_collection_name ⇒ Object
42 43 44 |
# File 'lib/brightcontent/base_controller_ext/default_actions.rb', line 42 def resource_collection_name resource_instance_name.pluralize end |
#resource_human_name(options = {}) ⇒ Object
46 47 48 |
# File 'lib/brightcontent/base_controller_ext/default_actions.rb', line 46 def resource_human_name( = {}) resource_class.model_name.human() end |
#resource_instance_name ⇒ Object
38 39 40 |
# File 'lib/brightcontent/base_controller_ext/default_actions.rb', line 38 def resource_instance_name resource_class.model_name.param_key end |
#show ⇒ Object
53 54 55 |
# File 'lib/brightcontent/base_controller_ext/default_actions.rb', line 53 def show redirect_to action: :edit end |
#update ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/brightcontent/base_controller_ext/default_actions.rb', line 73 def update if resource.update(resource_params) redirect_to resource_redirect_path, notice: t("flash.actions.update.notice", resource_name: resource_human_name) else render :edit end end |