aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/lines_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/lines_controller.rb')
-rw-r--r--app/controllers/lines_controller.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb
index 3a986b27c..83ab01674 100644
--- a/app/controllers/lines_controller.rb
+++ b/app/controllers/lines_controller.rb
@@ -1,4 +1,24 @@
class LinesController < InheritedResources::Base
defaults :resource_class => Chouette::Line
+ helper_method :sort_column, :sort_direction
+ respond_to :html
+ respond_to :xml
+ respond_to :json
+
+ protected
+
+ def collection
+ @lines ||= Chouette::Line.all.order_by [[sort_column.to_sym, sort_direction.to_sym]]
+ end
+
+ private
+
+ def sort_column
+ %w(name number).include?(params[:sort]) ? params[:sort] : "name"
+ end
+
+ def sort_direction
+ %w(asc desc).include?(params[:direction]) ? params[:direction] : "asc"
+ end
end