-
Notifications
You must be signed in to change notification settings - Fork 48
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
Media Ranker Katherine #45
base: master
Are you sure you want to change the base?
Conversation
add new work
Media RankerWhat We're Looking For
|
resources :works do | ||
resources :votes, only: [:create, :new, :show] | ||
end | ||
resources :users |
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.
don't think you need all 7 restful routes for users
- only index
and show
are needed for this project.
resources :users | ||
resources :votes do | ||
resources :works, only:[:create, :new, :show] | ||
resources :users |
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.
Not sure what the use case is here? This gives you all 7 routes for users from a single vote, but you can never view a vote on its own. I'm not sure you need routes for votes period, because you can create a vote via a patch to a work (e.g. an upvote route).
|
||
resources :works do | ||
resources :votes, only: [:create, :new, :show] | ||
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.
You need to keep an eye on your indentation. I know when you're writing code that it seems really unimportant, but the difference in readability between well indented code and poorly indented code is really significant.
|
||
|
||
<%= link_to "login", login_path %> | ||
<%= link_to "logout", logout_path, :method => :delete, :data => {:confirm => "You Sure?"}%> |
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 encourage you to dig into how you could use session to select which option to show in HTML. Giving a user both a login and logout button is not only confusing in terms of workflow, but it's visual clutter.
<ul class="nav app-header__user-nav-container"> | ||
|
||
<li class="nav-item app-header__nav_item"> | ||
<%= link_to "login", login_path %> |
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.
duplicate login button
@albums = Work.albums.order(votes_count: :desc).limit(10) | ||
@movies = Work.movies.order(votes_count: :desc).limit(10) | ||
@books = Work.books.order(votes_count: :desc).limit(10) | ||
@spotlight = Work.order(votes_count: :desc).first |
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.
You make this same call 4 times, and while you can argue that this isn't "heavy lifting" I'd still say that it's business logic as the business of MediaRanker is sorting things by vote count. You can do the same sort of work with a method in your model, and in the future that's what I'd like to see you do.
end | ||
|
||
def show | ||
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.
It's not a good practice to leave empty methods in your controller. If they aren't being used, delete these and the corresponding routes.
def index | ||
@albums = Work.where(category: "album") | ||
@movies = Work.where(category: "movie") | ||
@books = Work.where(category: "book")#paginate(page: params[:page], per_page: 10) |
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.
Your 'all works' page doesn't sort your media by votes because you don't call the sorting logic here. Again, you reduce the work you're doing and the likelihood of mistakes by creating code that relies on one method you use in many places.
|
||
|
||
|
||
|
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.
This would be a good place to use Flash to show error messages to the user.
# Assert | ||
expect(user).must_be_instance_of User | ||
expect(user.id).must_equal vote.user_id | ||
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.
You should be testing the uniqueness constraint here! Specific test cases I'd want to see:
- A user can have votes for two different works
- A work can have votes from two different users
- A user cannot vote for the same work twice
Media Ranker
Congratulations! You're submitting your assignment!
Comprehension Questions
session
andflash
? What is the difference between them?