Class: Nodes::ApplicationController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Nodes::ApplicationController
- Defined in:
- app/controllers/nodes/application_controller.rb
Direct Known Subclasses
Instance Method Summary collapse
- #init ⇒ Object
-
#sort ⇒ Object
ASC | DESC.
Instance Method Details
#init ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'app/controllers/nodes/application_controller.rb', line 5 def init @controller = params[:controller] if not %w(site user_sessions).include?(@controller) @object_name = @controller.singularize @model = @controller.singularize.split('/').map {|c| c.capitalize}.join('::').constantize if @controller @object = @model.find_by_id(params[:id]) if (params[:id] && @model) end end |
#sort ⇒ Object
ASC | DESC
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/nodes/application_controller.rb', line 15 def sort if session[:sort] == params[:field] #change sort direction if session[:sort_direction] == 'DESC' session[:sort_direction] = 'ASC' else session[:sort_direction] = 'DESC' end else # create new sort direction session[:sort] = params[:field] session[:sort_direction] = 'ASC' end list = @model.all if session[:sort_direction] == 'ASC' list.to_a.sort! do |one, two| a = one.send(session[:sort]) b = two.send(session[:sort]) (a and b) ? a <=> b : (a ? -1 : 1) end else list.to_a.sort! do |one, two| a = one.send(session[:sort]) b = two.send(session[:sort]) (b and a) ? b <=> a : (b ? -1 : 1) end end instance_variable_set("@#{@controller}", list) render action: :index end |