Closed swilliams closed 13 years ago
Is it just me or does the sorting for popularity not work? I'm working on a solution right now to test this out, but it threw errors at me when I tried it.
Forgot about that when I refactored the Votes into a separate class. I'll take care of it tonight. Poop.
I have a fix on my local copy of your branch.
Here's the patches:
diff --git a/showbot_web.rb b/showbot_web.rb index 25373a9..eed1242 100644 --- a/showbot_web.rb +++ b/showbot_web.rb @@ -19,12 +19,12 @@ end # ================= get '/' do - @suggestions = Suggestion.recent() + @suggestions = Suggestion.recent haml :index end get '/popular' do - @suggestions = Suggestion.recent().all(:order => [:votes.desc]) + @suggestions = Suggestion.recent.sort_by {|suggestion| -suggestion.votes.count} haml :index end diff --git a/lib/models/suggestion.rb b/lib/models/suggestion.rb index ceb5c9c..b80c6b1 100644 --- a/lib/models/suggestion.rb +++ b/lib/models/suggestion.rb @@ -58,8 +58,9 @@ class Suggestion end end - def Suggestion.recent(days_ago = 1) + def self.recent(days_ago = 1) from = DateTime.now - days_ago - Suggestion.all(:created_at.gt => from).all(:order => [:created_at.desc]) + all(:created_at.gt => from).all(:order => [:created_at.desc]) end + end
Hey man,
I got some basic voting in. The UI kind of sucks: I stole reddit's up arrow, and couldn't quite figure out how to make it work with your css, but the functionality is there. It simply checks IP address and will only let you vote once per suggestion. Feel free to change it around and outright reject altogether :).
-Scott Williams "swilliams"