Class: LotusAdmin::ResourceController
- Inherits:
-
AuthenticatedController
- Object
- ActionController::Base
- ApplicationController
- AuthenticatedController
- LotusAdmin::ResourceController
- Defined in:
- app/controllers/lotus_admin/resource_controller.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #create(&block) ⇒ Object
- #destroy(&block) ⇒ Object
- #edit(&block) ⇒ Object
- #index(&block) ⇒ Object
- #new(&block) ⇒ Object
- #show(&block) ⇒ Object
- #update(&block) ⇒ Object
Class Method Details
.manages(model_class) ⇒ Object
8 9 10 |
# File 'app/controllers/lotus_admin/resource_controller.rb', line 8 def self.manages(model_class) self._resource_class = model_class end |
Instance Method Details
#create(&block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/lotus_admin/resource_controller.rb', line 26 def create(&block) self.resource = build_resource(permitted_params) (resource) if using_pundit? respond_to do |format| format.html if block.present? block.call(format) else if resource.save redirect_to after_create_redirect, notice: "Created new #{ resource_class.model_name.human } successfully" else render :new end end end end |
#destroy(&block) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/lotus_admin/resource_controller.rb', line 94 def destroy(&block) (resource) if using_pundit? respond_to do |format| format.html if block.present? block.call(format) else if resource.destroy flash[:notice] = "#{ resource_class.model_name.human } has been removed" else flash[:error] = "There was an error removing that #{ resource_class.model_name.human }" end redirect_to after_destroy_redirect end end end |
#edit(&block) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/lotus_admin/resource_controller.rb', line 46 def edit(&block) (resource) if using_pundit? if block.present? block.call else render :edit end end |
#index(&block) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/lotus_admin/resource_controller.rb', line 74 def index(&block) (resource_class) if using_pundit? respond_to do |format| format.html block.call(format) if block.present? end end |
#new(&block) ⇒ Object
18 19 20 21 22 23 24 |
# File 'app/controllers/lotus_admin/resource_controller.rb', line 18 def new(&block) self.resource = build_resource (resource) if using_pundit? block.call if block.present? end |
#show(&block) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'app/controllers/lotus_admin/resource_controller.rb', line 84 def show(&block) (resource) if using_pundit? respond_to do |format| format.html block.call(format) if block.present? end end |
#update(&block) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/lotus_admin/resource_controller.rb', line 56 def update(&block) (resource) if using_pundit? respond_to do |format| format.html if block.present? block.call(format) else if resource.update(permitted_params) redirect_to after_update_redirect, notice: "Updated #{ resource_class.model_name.human } successfully" else render :edit end end end end |