Class: Glib::HomeController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Glib::HomeController
- Defined in:
- app/controllers/glib/home_controller.rb
Instance Method Summary collapse
- #index_order(prop_name, direction) ⇒ Object
- #init_orders ⇒ Object
- #json_ui_garage ⇒ Object
- #reversed_order(order) ⇒ Object
- #reversed_order_params(prop_name) ⇒ Object
Instance Method Details
#index_order(prop_name, direction) ⇒ Object
47 48 49 50 51 52 53 |
# File 'app/controllers/glib/home_controller.rb', line 47 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_orders ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'app/controllers/glib/home_controller.rb', line 38 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_garage ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/glib/home_controller.rb', line 8 def json_ui_garage init_orders @path_prefix = 'json_ui/garage' @__glib_head_code =<<-eos <style> .custom-container .pages-body > div > .panels-responsive { max-width: 800px; width: 100%; margin-right: auto; margin-left: auto; } .rounded-corner { border-radius: 16px; } /* Make sure the hover highlight effect also has rounded corners */ .rounded-corner:hover:after { border-radius: 16px; } </style> eos # 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
55 56 57 |
# File 'app/controllers/glib/home_controller.rb', line 55 def reversed_order(order) order.to_sym == :asc ? :desc : :asc end |
#reversed_order_params(prop_name) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/glib/home_controller.rb', line 59 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 |