Skip to content

Commit

Permalink
add bicycle & driving type to return projects in diff order
Browse files Browse the repository at this point in the history
  • Loading branch information
apprentice1988 committed Oct 24, 2015
1 parent f3688da commit 790f3d5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
14 changes: 13 additions & 1 deletion app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class ProjectsController < ApplicationController

def index
@projects = Project.all
@projects = []
address_order.each {|x| @projects << Project.find_by(address: x)}
end

def show
Expand Down Expand Up @@ -44,4 +45,15 @@ def result
@project = Project.find(params[:id])
end

private
def address_order
if params[:type] == 'walking'
['青年大教堂', '红楼', '省博', '黄鹤楼', '武汉大学', '昙华林']
elsif params[:type] == 'bicycle'
%w(武汉大学 昙华林 黄鹤楼 省博 青年大教堂 红楼)
else
%w(黄鹤楼 省博 昙华林 红楼 青年大教堂 武汉大学)
end
end

end
10 changes: 4 additions & 6 deletions app/views/projects/index.rabl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
collection :@projects

attributes :id, :name, :description, :sponsor, :address, :background, :image, :unit_type, :unit_steps_count

node(:distance) do |pro|
"#{pro.distance([params[:coordinates].try(&:first).to_f, params[:coordinates].try(&:last).to_f])} km"
node(:projects) do
@projects.map do |v|
partial 'projects/project', object: v
end
end
5 changes: 5 additions & 0 deletions app/views/projects/project.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
attributes :id, :name, :description, :sponsor, :address, :background, :image, :unit_type, :unit_steps_count

node(:distance) do |pro|
"#{pro.distance([params[:coordinates].try(&:first).to_f, params[:coordinates].try(&:last).to_f])} km"
end

0 comments on commit 790f3d5

Please sign in to comment.