Module: Ext::Controllers::Paginate::InstanceMethods

Defined in:
lib/ext/controllers/paginate.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



18
19
20
21
# File 'lib/ext/controllers/paginate.rb', line 18

def index
  @opts = index_options
  render :inline=>"<%= ext_include %><%= ext_paginate @opts %><%= ext_grid %>"
end

#listObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ext/controllers/paginate.rb', line 23

def list
  opts = {
    :select => options[:select],
    :offset => [params[:start].to_i-1, 0].max,
    :limit  => [params[:limit].to_i, options[:limit]].max,
    :order  => sorts.blank? ? nil : sorts.map{|i| "%s %s" % [i, params[:dir]]}.join(', '),
  }
  json = {
    "count" => count.to_s,
    "items" => search(opts).map{|item| data(item)},
  }.to_json
  render :text=>json
end

#showObject



37
38
39
40
# File 'lib/ext/controllers/paginate.rb', line 37

def show
  record = options[:model].find(params[:id])
  render :text=>data(record).to_json
end

#updateObject



42
43
44
45
46
47
# File 'lib/ext/controllers/paginate.rb', line 42

def update
  pkey = options[:model].primary_key
  attributes = CGIMethods.parse_request_parameters(request.cgi.params)
  options[:model].update(params[pkey], attributes)
  render :nothing=>true
end