Sha256: c268379e243bdfb8cd6bfe850104861c0cea217c011fc35ae02eb5d0a6abe870

Contents?: true

Size: 605 Bytes

Versions: 3

Compression:

Stored size: 605 Bytes

Contents

require 'will_paginate/array'

class DataController < ApplicationController
  Datum = Struct.new(:id, :name)

  DATA = (1..100).map do |i|
    Datum.new(i, "Name #{i}")
  end

  def DATA.order(arg)
    column, direction = arg.split
    sorted_data = case column
    when 'name' then DATA.sort_by { |datum| datum[1] }
    when 'id' then DATA
    else raise "Invalid column: #{column}"
    end
    case direction
    when 'asc' then sorted_data
    when 'desc' then sorted_data.reverse
    else raise "Invalid direction: #{direction}"
    end
  end

  def index
    paginated_table(:data => DATA)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
paginated_table-0.0.3 test/dummy/app/controllers/data_controller.rb
paginated_table-0.0.2 test/dummy/app/controllers/data_controller.rb
paginated_table-0.0.1 test/dummy/app/controllers/data_controller.rb