Class: Glib::HomeController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/glib/home_controller.rb

Instance Method Summary collapse

Instance Method Details

#index_order(prop_name, direction) ⇒ Object



27
28
29
30
31
32
33
# File 'app/controllers/glib/home_controller.rb', line 27

def index_order(prop_name, direction)
  # In a real app, apply ordering to the model. For example:
  # @users = @users.order(prop_name => direction)

  # Garage example
  @order_headings[prop_name] = direction
end

#init_ordersObject



18
19
20
21
22
23
24
25
# File 'app/controllers/glib/home_controller.rb', line 18

def init_orders
  @order_headings = {}
  @orders = params[:orders] || []
  @orders.each do |order|
    prop_name, direction = order.split('-')
    index_order(prop_name, direction)
  end
end

#json_ui_garageObject



8
9
10
11
12
13
14
15
16
# File 'app/controllers/glib/home_controller.rb', line 8

def json_ui_garage
  init_orders

  @path_prefix = 'json_ui/garage'

  # We can't use prepend_view_path because it affects the app, not the gem
  path = "#{@path_prefix}/#{params[:path] || 'home/index'}"
  render path
end

#reversed_order(order) ⇒ Object



35
36
37
# File 'app/controllers/glib/home_controller.rb', line 35

def reversed_order(order)
  order.to_sym == :asc ? :desc : :asc
end

#reversed_order_params(prop_name) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/glib/home_controller.rb', line 39

def reversed_order_params(prop_name)
  prop_value = :asc
  remaining = @orders.reject do |o|
    tuple = o.split('-')
    if tuple.first == prop_name.to_s
      prop_value = reversed_order(tuple.second)
      true
    end
  end
  # Sort the params to produce predictable URLs which are useful for SEO
  (["#{prop_name}-#{prop_value}"] + remaining).sort
end