-
Notifications
You must be signed in to change notification settings - Fork 47
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
Ports - Heather #27
base: master
Are you sure you want to change the base?
Ports - Heather #27
Conversation
…. View pages for works.
… in application view
Media RankerWhat We're Looking For
Well done on this, Heather! This project was huge and your submission is great. Your controllers and controller tests are great! I have no complaints on those! I'm really happy with the model code, the model tests, and all of the moving parts, too. Great job on hitting the learning goals. All of my comments are really about the following things:
I actually figured out what was going on!
Also, overall, your indentation always got a little weird in the view code (see the That being said, great submission. Well done! |
@@ -0,0 +1,7 @@ | |||
class HomepagesController < ApplicationController | |||
def index | |||
def index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm?! Why is an index
method defined inside of the index
method?! Actually, this is what produced the really interesting bug!!
has_many :votes, dependent: :destroy | ||
|
||
def self.top_ten(type) | ||
array_by_type = self.where(category: type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these variables names could be better. If it were me, I would rename array_by_type
to simply works
or categorized_works
, and array_by_votes
to sorted_works
return array_by_votes[0..9] | ||
end | ||
else | ||
return array_by_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... array_by_type
(since it comes from a where
call) will always be an array... even an empty array. If that's the case, do we need the if ... else
here? Consider the following refactor of the method:
def self.top_ten(type)
array_by_type = self.where(category: type)
array_by_votes = array_by_type.sort_by { |work| -work.votes.count }
return array_by_votes[0..9]
end
The tests still pass! When you are ready, take some time to think about why this still works and is effectively the same thing as your current code
spotlight = sorted_works.first | ||
|
||
return spotlight | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this code! It's concise and clean. How would you feel if you did the following refactor:
def self.media_spotlight
sorted_works = self.all.sort_by { |work| -work.votes.count }
return sorted_works.first
end
<%= link_to "Media Ranker", homepages_path %> | ||
<small>Ranking the Best of Everything</small> | ||
</h1> | ||
<% if flash.count > 0 %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably would be way better to insert flash
outside of the header
tag to match the model website
<%= render partial: "indextable", locals: { | ||
header_category: "Albums:", | ||
category: "album" | ||
} %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic use of partials! :D
Rails.application.routes.draw do | ||
root to: "homepages#index" | ||
|
||
get "homepages/index" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you did resoures :homepages, only: [:index]
below, you don't need this route. Also, it doesn't direct anyone anywhere! It's not quite the right syntax
Media Ranker
Congratulations! You're submitting your assignment!
Comprehension Questions
session
andflash
? What is the difference between them?