Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rachael water class #36

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
54fec0e
Initial rails setup
RachaelGomez Nov 11, 2020
ddb6426
seeded database and made Works controller and model
RachaelGomez Nov 11, 2020
c0e91d2
fixed homepage but spotlight isn't working. made new and index but ne…
RachaelGomez Nov 13, 2020
1e1d104
added edit and delete and users model and controller
RachaelGomez Nov 14, 2020
877a5f7
set up users and login and created votes controller and model
RachaelGomez Nov 14, 2020
dbe73ce
votes won't save
RachaelGomez Nov 15, 2020
3a77c1c
Votes still won't save but now I have a count so I can see them not s…
RachaelGomez Nov 15, 2020
a81295a
still playing with vote. added flash to edit
RachaelGomez Nov 15, 2020
200b92e
Votes finally count. user nil conditional not working.
RachaelGomez Nov 15, 2020
50d5f4f
user can't vote more than once. spotlight working. top ten not working.
RachaelGomez Nov 16, 2020
0b3e09d
all top 10s are working
RachaelGomez Nov 16, 2020
5135d86
media is sorted by number of votes
RachaelGomez Nov 16, 2020
0181bae
added flash for deleted media
RachaelGomez Nov 16, 2020
eeebffc
just realized edit is no longer working
RachaelGomez Nov 16, 2020
45b276b
fixed edit. Trying to fix heroku app
RachaelGomez Nov 16, 2020
afc735e
fixed heroku app
RachaelGomez Nov 16, 2020
deb7e2d
set up yml files for testing. Didn't set up votes because of id weird…
RachaelGomez Nov 16, 2020
5a080fc
tried to fix top ten for albums and movies but am not seeing the prob…
RachaelGomez Nov 16, 2020
aa0ac7e
making some tests. Validations down
RachaelGomez Nov 16, 2020
7858a3e
finishing up tests
RachaelGomez Nov 16, 2020
d4d3980
working on copying the website css
RachaelGomez Nov 16, 2020
542e13f
as good as it's gonna get
RachaelGomez Nov 16, 2020
e08ac48
added user show page and show work helper method
RachaelGomez Nov 16, 2020
1e4a348
added all works that a user has voted for
RachaelGomez Nov 16, 2020
fdc4f48
made lookup method for users and now have list of users who have vote…
RachaelGomez Nov 16, 2020
5d4e48d
fixed a typo
RachaelGomez Nov 16, 2020
c668043
added upvote button to work page
RachaelGomez Nov 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
all top 10s are working
RachaelGomez committed Nov 16, 2020
commit 0b3e09d9ac567c698a98e977908399e1c1311d44
40 changes: 35 additions & 5 deletions app/models/work.rb
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@ class Work < ApplicationRecord
validates :creator, presence: true

def self.sort_votes
work = Work.all
sorted_work = work.sort_by{|work| work.votes.count}.reverse
works = Work.all
sorted_work = works.sort_by{|work| work.votes.count}.reverse
return sorted_work
end

@@ -19,9 +19,39 @@ def self.spotlight
return spotlight
end

def self.top_ten
def self.top_ten_books

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods are ok, but you can dry them up.

  def self.top_ten(cateogry)
    return Work.where(category: category).sort_by { |work| work.votes.count }.reverse.first(10)
  end

Or this one which uses Postgres to sort (google search to get it).

  def self.top_ten(cateogry)
    return Work.where(category: category).order(Arel.sql('COUNT(votes.id)DESC'))
  end

work = Work.all
books = []
work.each do |work|
if work.category == "book"
books << work
end
end
top_ten = books.sort_by{|work| work.votes.count}.reverse
return top_ten[0...10]
end

def self.top_ten_albums
work = Work.all
by_category = []
work.each do |work|
if work.category == "albums"
books << work
end
end
top_ten = by_category.sort_by{|work| work.votes.count}.reverse
return top_ten[0...10]
end

def self.top_ten_movies
work = Work.all
top_ten = work.sort_votes
return top_ten
by_category = []
work.each do |work|
if work.category == "movies"
books << work
end
end
top_ten = by_category.sort_by{|work| work.votes.count}.reverse
return top_ten[0...10]
end
end
6 changes: 3 additions & 3 deletions app/views/homepages/index.html.erb
Original file line number Diff line number Diff line change
@@ -7,22 +7,22 @@
<div>
<h4>
Top 10 Books!
<% @works.top_ten[0..10].each do |work| %>
<% @works.top_ten_books.each do |work| %>
<% if work.category == "book" %>
<li> <%= link_to work.title, work_path(work) %></li>
<% end %>
<% end %>
</h4>
<h4>
Top 10 Movies!
<% @works.each do |work| %>
<% @works.top_ten_movies.each do |work| %>
<% if work.category == "movie" %>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here if the top_ten_movies method returns only movies?

<li> <%= link_to work.title, work_path(work) %></li>
<% end %>
<% end %>
<h4>
Top 10 Albums!
<% @works.each do |work| %>
<% @works.top_ten_albums.each do |work| %>
<% if work.category == "album" %>
<li> <%= link_to work.title, work_path(work) %></li>
<% end %>