Conversation
Media RankerWhat We're Looking For
|
| @top_movies = Work.top_ten("movie") | ||
| @top_albums = Work.top_ten("album") | ||
|
|
||
| @top_media = Work.top_media |
There was a problem hiding this comment.
Your custom model methods make this controller action very clean - good work!
| def media_votes | ||
| combined_works = [] | ||
|
|
||
| self.votes.each do |vote| |
There was a problem hiding this comment.
Why not use a has_many :through relationship for this?
| class Vote < ApplicationRecord | ||
| belongs_to :user | ||
| belongs_to :work | ||
|
|
There was a problem hiding this comment.
If you wanted to make it so that each user can only vote for a given work once, you could do it with a validation here.
| def self.top_ten(category) | ||
| top_ten = self.ranked_media(category) | ||
| top_ten.first(10) | ||
| end |
There was a problem hiding this comment.
I love the way the methods in this model build on each other little by little - this is a great example of functional decomposition.
| <section class = "media-table"> | ||
| <h4>Books</h4> | ||
| <table> | ||
| <thead> |
There was a problem hiding this comment.
You have the same code to show a list of works repeated 3 times. Could you use a view partial or a loop to DRY this up?
| <h2>Edit this Work</h2> | ||
|
|
||
|
|
||
| <%= form_with model: @work do |f| %> |
There was a problem hiding this comment.
You have the same form code here and in new.html.erb. You should be using a partial to DRY this up.
| end | ||
|
|
||
| resources :users | ||
|
|
There was a problem hiding this comment.
Do you need all 7 RESTful routes for user?
|
|
||
| 50.times do | ||
| book = Work.new(title: "Title#{x}", category: "Book") | ||
| book.save |
There was a problem hiding this comment.
I like this idea - test it by making a bunch of books in a loop. Good work!
| describe 'top_ten' do | ||
|
|
||
| it 'returns only 10 entries of each category' do | ||
|
|
There was a problem hiding this comment.
I would also be interested in the following cases:
- What if there are no works of that category?
- What if there's a tie for last place, e.g. works 9, 10 and 11 all have 0 votes?
| describe 'top_media' do | ||
|
|
||
| it 'has the most votes out of all media' do | ||
|
|
There was a problem hiding this comment.
I would also be interested in:
- What happens if there are no works?
- What happens if there are works but no votes?
- What happens if two works have the same number of votes?
Media Ranker
Congratulations! You're submitting your assignment!
Comprehension Questions
sessionandflash? What is the difference between them?