Class: Admin::ResourceController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::ResourceController
- Extended by:
- TrustyCms::ResourceResponses
- Defined in:
- app/controllers/admin/resource_controller.rb
Direct Known Subclasses
AssetsController, LayoutsController, PageAttachmentsController, PageFieldsController, PagePartsController, PagesController, SitesController, SnippetsController, UsersController
Class Method Summary collapse
- .model_class(model_class = nil) ⇒ Object
-
.paginate_models(options = {}) ⇒ Object
call paginate_models to declare that will_paginate should be used in the index view options specified here are accessible in the view by calling will_paginate_options eg.
Instance Method Summary collapse
- #destroy ⇒ Object
- #index ⇒ Object
-
#paginated? ⇒ Boolean
a convenience method that returns true if paginate_models has been called on this controller class and can be used to make display decisions in controller and view.
-
#pagination_parameters ⇒ Object
return a hash of page and per_page that can be used to build a will_paginate collection the per_page figure can be set in several ways: request parameter > declared by paginate_models > default set in config entry @admin.pagination.per_page@ > overall default of 50.
-
#will_paginate_options ⇒ Object
returns a hash of options that can be passed to will_paginate the @pagination_for@ helper method calls @will_paginate_options@ unless other options are supplied.
Methods included from TrustyCms::ResourceResponses
Class Method Details
.model_class(model_class = nil) ⇒ Object
74 75 76 |
# File 'app/controllers/admin/resource_controller.rb', line 74 def self.model_class(model_class = nil) @model_class ||= (model_class || controller_name).to_s.singularize.camelize.constantize end |
.paginate_models(options = {}) ⇒ Object
call paginate_models to declare that will_paginate should be used in the index view options specified here are accessible in the view by calling will_paginate_options eg.
Class MyController < Admin::ResourceController
paginate_models :per_page => 100
85 86 87 88 89 |
# File 'app/controllers/admin/resource_controller.rb', line 85 def self.paginate_models( = {}) @@paginated = true @@will_paginate_options = .slice(:class, :previous_label, :next_label, :inner_window, :outer_window, :separator, :container).merge(param_name: :p) @@default_per_page = [:per_page] end |
Instance Method Details
#destroy ⇒ Object
69 70 71 72 |
# File 'app/controllers/admin/resource_controller.rb', line 69 def destroy model.destroy response_for :destroy end |
#index ⇒ Object
48 49 50 |
# File 'app/controllers/admin/resource_controller.rb', line 48 def index response_for :plural end |
#paginated? ⇒ Boolean
a convenience method that returns true if paginate_models has been called on this controller class and can be used to make display decisions in controller and view
104 105 106 |
# File 'app/controllers/admin/resource_controller.rb', line 104 def paginated? self.class.paginated == true && params[:pp] != 'all' end |
#pagination_parameters ⇒ Object
return a hash of page and per_page that can be used to build a will_paginate collection the per_page figure can be set in several ways: request parameter > declared by paginate_models > default set in config entry @admin.pagination.per_page@ > overall default of 50
113 114 115 116 117 118 119 120 |
# File 'app/controllers/admin/resource_controller.rb', line 113 def pagination_parameters pp = params[:pp] || TrustyCms.config['admin.pagination.per_page'] pp = (self.class.default_per_page || 50) if pp.blank? { page: (params[:p] || 1).to_i, per_page: pp.to_i, } end |
#will_paginate_options ⇒ Object
returns a hash of options that can be passed to will_paginate the @pagination_for@ helper method calls @will_paginate_options@ unless other options are supplied.
pagination_for(@events)
96 97 98 |
# File 'app/controllers/admin/resource_controller.rb', line 96 def self.class. || {} end |