Module: Effective::CrudController
- Extended by:
- ActiveSupport::Concern
- Included in:
- WizardController
- Defined in:
- app/controllers/concerns/effective/crud_controller.rb,
app/controllers/concerns/effective/crud_controller/dsl.rb,
app/controllers/concerns/effective/crud_controller/save.rb,
app/controllers/concerns/effective/crud_controller/paths.rb,
app/controllers/concerns/effective/crud_controller/users.rb,
app/controllers/concerns/effective/crud_controller/actions.rb,
app/controllers/concerns/effective/crud_controller/respond.rb,
app/controllers/concerns/effective/crud_controller/submits.rb,
app/controllers/concerns/effective/crud_controller/permitted_params.rb
Defined Under Namespace
Modules: Actions, ClassMethods, Dsl, Paths, PermittedParams, Respond, Save, Submits, Users
Constant Summary
Constants included from PermittedParams
Instance Method Summary collapse
- #action_missing(action, *args, &block) ⇒ Object
- #effective_resource(safe: false) ⇒ Object
- #nested_datatable_action(action = nil) ⇒ Object
- #resource ⇒ Object
- #resource=(instance) ⇒ Object
-
#resource_klass ⇒ Object
Thing.
- #resources ⇒ Object
- #resources=(instance) ⇒ Object
Methods included from Users
Methods included from Submits
#_insert_button, #_insert_on, #_insert_submit, #buttons, #ons, #submits
Methods included from Save
#commit_action, #duplicate_resource, #notify_exception, #reload_resource, #resource_flash, #save_resource
Methods included from Respond
#respond_with_error, #respond_with_success
Methods included from PermittedParams
#resource_active_model_permitted_params, #resource_admin_permitted_params, #resource_permitted_params
Methods included from Paths
#referer_redirect_path, #resource_action_path, #resource_destroy_path, #resource_duplicate_path, #resource_edit_path, #resource_index_path, #resource_new_path, #resource_redirect_error_path, #resource_redirect_path, #resource_show_path, #specific_redirect_error_path?, #specific_redirect_path?
Methods included from Actions
#collection_action, #create, #destroy, #edit, #index, #member_action, #new, #show, #update
Instance Method Details
#action_missing(action, *args, &block) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/concerns/effective/crud_controller.rb', line 67 def action_missing(action, *args, &block) effective_resource = self.effective_resource(safe: true) return super if effective_resource.blank? action = action.to_sym if effective_resource.member_actions.include?(action) return member_action(action) end if effective_resource.collection_actions.include?(action) return collection_action(action) end params[:id].present? ? member_action(action) : collection_action(action) end |
#effective_resource(safe: false) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/concerns/effective/crud_controller.rb', line 47 def effective_resource(safe: false) @_effective_resource ||= begin relation = instance_exec(&resource_scope_relation) if respond_to?(:resource_scope_relation) if respond_to?(:resource_scope_relation) unless relation.kind_of?(ActiveRecord::Relation) || (relation.kind_of?(Class) && relation.ancestors.include?(ActiveModel::Model)) raise('resource_scope must return an ActiveRecord::Relation or class including ActiveModel::Model') end end resource = Effective::Resource.new(controller_path, relation: relation) unless resource.relation.kind_of?(ActiveRecord::Relation) || resource.active_model? raise("unable to build resource_scope for #{resource.klass || 'unknown klass'}. Please name your controller to match an existing model, or manually define a resource_scope.") unless safe else resource end end end |
#nested_datatable_action(action = nil) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'app/controllers/concerns/effective/crud_controller/actions.rb', line 258 def nested_datatable_action(action = nil) Rails.logger.info "Processed by Effective::CrudController#nested_datatable_action" raise('expected a GET request') unless request.get? raise('expected @datatable to be present') if @datatable.nil? action ||= action_name EffectiveResources.(self, :index, @datatable) @page_title ||= @datatable.datatable_name respond_to do |format| format.html do html_template = action if template_present?(action, format: :html) render(html_template || 'index') end format.js do html_template = [controller_path, action].join('/') if template_present?(action, format: :html) template = template_present?(action) ? action : 'nested_datatable_action' render(template, formats: :js, locals: { action: action, html_template: html_template }) end end end |
#resource ⇒ Object
31 32 33 |
# File 'app/controllers/concerns/effective/crud_controller.rb', line 31 def resource # @thing instance_variable_get("@#{resource_name}") end |
#resource=(instance) ⇒ Object
35 36 37 |
# File 'app/controllers/concerns/effective/crud_controller.rb', line 35 def resource=(instance) instance_variable_set("@#{resource_name}", instance) end |
#resource_klass ⇒ Object
Thing
84 85 86 |
# File 'app/controllers/concerns/effective/crud_controller.rb', line 84 def resource_klass # Thing effective_resource.klass end |
#resources ⇒ Object
39 40 41 |
# File 'app/controllers/concerns/effective/crud_controller.rb', line 39 def resources # @things send(:instance_variable_get, "@#{resource_plural_name}") end |
#resources=(instance) ⇒ Object
43 44 45 |
# File 'app/controllers/concerns/effective/crud_controller.rb', line 43 def resources=(instance) send(:instance_variable_set, "@#{resource_plural_name}", instance) end |