Class: Admin::ResourceController
- Inherits:
-
AdminController
- Object
- AdminController
- Admin::ResourceController
- Extended by:
- Radiant::ResourceResponses
- Defined in:
- app/controllers/admin/resource_controller.rb
Direct Known Subclasses
LayoutsController, PageFieldsController, PagePartsController, PagesController, 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 Radiant::ResourceResponses
Class Method Details
.model_class(model_class = nil) ⇒ Object
72 73 74 |
# File 'app/controllers/admin/resource_controller.rb', line 72 def self.model_class(model_class = nil) @model_class ||= (model_class || self.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
83 84 85 86 87 |
# File 'app/controllers/admin/resource_controller.rb', line 83 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
67 68 69 70 |
# File 'app/controllers/admin/resource_controller.rb', line 67 def destroy model.destroy response_for :destroy end |
#index ⇒ Object
46 47 48 |
# File 'app/controllers/admin/resource_controller.rb', line 46 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
101 102 103 |
# File 'app/controllers/admin/resource_controller.rb', line 101 def paginated? self.class.paginated == true 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
109 110 111 112 113 114 |
# File 'app/controllers/admin/resource_controller.rb', line 109 def pagination_parameters { :page => (params[:p] || 1).to_i, :per_page => (params[:pp] || self.class.default_per_page || Radiant::Config['admin.pagination.per_page'] || 50).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)
94 95 96 |
# File 'app/controllers/admin/resource_controller.rb', line 94 def self.class. || {} end |