Module: Effective::CrudController
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/controllers/concerns/effective/crud_controller.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/concerns/effective/crud_controller.rb', line 71 def create self.resource ||= resource_class.new(send(resource_params_method_name)) @page_title ||= "New #{resource_name.titleize}" EffectiveResources.(self, :create, resource) if resource.save flash[:success] = "Successfully created #{resource_human_name}" redirect_to(resource_redirect_path) else flash.now[:danger] = "Unable to create #{resource_human_name}: #{resource.errors..to_sentence}" render :new end end |
#destroy ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/controllers/concerns/effective/crud_controller.rb', line 115 def destroy self.resource = resource_class.find(params[:id]) @page_title = "Destroy #{resource}" EffectiveResources.(self, :destroy, resource) if resource.destroy flash[:success] = "Successfully deleted #{resource_human_name}" else flash[:danger] = "Unable to delete #{resource_human_name}: #{resource.errors..to_sentence}" end request.referer.present? ? redirect_to(request.referer) : redirect_to(send(resource_index_path)) end |
#edit ⇒ Object
93 94 95 96 97 98 |
# File 'app/controllers/concerns/effective/crud_controller.rb', line 93 def edit self.resource ||= resource_class.find(params[:id]) @page_title ||= "Edit #{resource}" EffectiveResources.(self, :edit, resource) end |
#index ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/concerns/effective/crud_controller.rb', line 53 def index @page_title ||= resource_plural_name.titleize EffectiveResources.(self, :index, resource_class.new) self.resources ||= resource_class.all if resource_datatable_class @datatable ||= resource_datatable_class.new(self, resource_datatable_attributes) end end |
#new ⇒ Object
64 65 66 67 68 69 |
# File 'app/controllers/concerns/effective/crud_controller.rb', line 64 def new self.resource ||= resource_class.new @page_title ||= "New #{resource_name.titleize}" EffectiveResources.(self, :new, resource) end |
#show ⇒ Object
86 87 88 89 90 91 |
# File 'app/controllers/concerns/effective/crud_controller.rb', line 86 def show self.resource ||= resource_class.find(params[:id]) @page_title ||= resource.to_s EffectiveResources.(self, :show, resource) end |
#update ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/controllers/concerns/effective/crud_controller.rb', line 100 def update self.resource ||= resource_class.find(params[:id]) @page_title = "Edit #{resource}" EffectiveResources.(self, :update, resource) if resource.update_attributes(send(resource_params_method_name)) flash[:success] = "Successfully updated #{resource_human_name}" redirect_to(resource_redirect_path) else flash.now[:danger] = "Unable to update #{resource_human_name}: #{resource.errors..to_sentence}" render :edit end end |