Class: Admin::ResourceController

Inherits:
AdminController
  • Object
show all
Extended by:
Radiant::ResourceResponses
Defined in:
app/controllers/admin/resource_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Radiant::ResourceResponses

extended, responses

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(options={})
  @@paginated = true
  @@will_paginate_options = options.slice(:class, :previous_label, :next_label, :inner_window, :outer_window, :separator, :container).merge(:param_name => :p)
  @@default_per_page = options[:per_page]
end

Instance Method Details

#destroyObject



67
68
69
70
# File 'app/controllers/admin/resource_controller.rb', line 67

def destroy
  model.destroy
  response_for :destroy
end

#indexObject



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

Returns:

  • (Boolean)


101
102
103
# File 'app/controllers/admin/resource_controller.rb', line 101

def paginated?
  self.class.paginated == true
end

#pagination_parametersObject

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_optionsObject

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 will_paginate_options
  self.class.will_paginate_options || {}
end