-
Notifications
You must be signed in to change notification settings - Fork 52
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
India - Water #48
base: master
Are you sure you want to change the base?
India - Water #48
Conversation
… for works controller
Create user
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.
Media Ranker
Functional Requirements: Manual Testing
Feedback updated on 12/1 is in ()
Criteria | yes/no |
---|---|
Before logging in | -- |
1. On index page, there are at most 10 pieces of media on three lists, and a Media Spotlight | ✔️ |
2. Can go into a work's show page | ✔️ |
3. Verify unable to vote on a work, and get a flash message | (✔️) Voting functionality not implemented yet. |
4. Can edit this work successfully, and get a flash message | No flash message |
5. Can go to "View all media" page and see three lists of works, sorted by vote | (Not sorted by vote) ✔️ |
6. Verify unable to create a new work when the form is empty, and details about the validation errors are visible to the user through a flash message | (✔️ - details of validation errors are not shows, see in-line comment) create method missing |
7. Can create a new work successfully. Note the URL for this work's show page | (✔️) create method was not created |
8. Can delete this work successfully | ✔️ |
9. Going back to the URL of this deleted work's show page produces a 404 or some redirect behavior (and does not try to produce a broken view) | ✔️ |
10. Verify that the "View all users" page lists no users | Incomplete |
Log in | -- |
11. Logging in with a valid name changes the UI to "Logged in as" and "Logout" buttons | ✔️ |
12. Your username is listed in "View all users" page | (✔️) Incomplete |
13. Verify that number of votes determines the Media Spotlight | (✔️) Voting functionality not implemented yet. |
14. Voting on several different pieces of media affects the "Votes" tables shown in the work's show page and the user's show page | (✔️-- good work flashing the validation errors) Voting functionality not implemented yet. |
15. Voting on the same work twice produces an error and flash message, and there is no extra vote | Voting functionality not implemented yet. |
Log out | -- |
16. Logging out showed a flash message and changed the UI | ✔️ |
17. Logging in as a new user creates a new user | ✔️ |
18. Logging in as an already existing user has a specific flash message | ✔️ |
Major Learning Goals/Code Review
Criteria | yes/no |
---|---|
1. Sees the full development cycle including deployment, and the app is deployed to Heroku | Not deployed yet |
2. Practices full-stack development and fulfilling story requirements: the styling, look, and feel of the app is similar to the original Media Ranker | No styles added |
3. Practices git with at least 25 small commits and meaningful commit messages | ✔️ |
Previous Rails learning, Building Complex Model Logic, DRYing up Rails Code
Criteria | yes/no |
---|---|
4. Routes file uses resources for works |
✔️ |
5. Routes file shows intention in limiting routes for voting, log-in functionality, and users | ✔️ |
6. The homepage view, all media view, and new works view use semantic HTML | ✔️ |
7. The homepage view, all media view, and new works view use partials when appropriate | See in-line comment for suggestion. |
8. The model for media (likely named work.rb ) has_many votes |
(✔️) Voting functionality not implemented yet. |
9. The model for media has methods to describe business logic, specifically for top ten and top media, possibly also for getting works by some category | (✔️)No model methods |
10. Some controller, likely the ApplicationController , has a controller filter for finding a logged in user |
(✔️)See in-line comment. |
11. Some controller, likely the WorksController , has a controller filter for finding a work |
See in-line comment |
12. The WorksController uses strong params |
✔️ |
13. The WorksController 's code style is clean, and focused on working with requests, responses, params , session , flash |
✔️ |
Testing Rails Apps
Criteria | yes/no |
---|---|
14. There are valid fixtures files used for users, votes, and works | (✔️)No tests yet |
15. User model has tests with sections on validations (valid and invalid) and relationships (has votes) | (✔️)No tests yet |
16. Vote model has tests with sections on validations (valid and invalid) and relationships (belongs to a user, belongs to a vote) | (✔️)No tests yet |
17. Work model has tests with sections on validations (valid and invalid) and relationships (has votes) | (✔️ - missing relationship tests)No tests yet |
18. Work model has tests with a section on all business logic methods in the model, including their edge cases | (✔️)No tests yet |
Overall Feedback
(Great job working through this project. You've implemented the login/logout feature, upvote feature, fixtures, and model methods. I've left some in-line comment for suggestion on how to use partial views and controller filters to DRY up your code. Please let me know if you have any questions. Keep up the hard work!)
You are off to a good start with this project. It is great to see that you met the learning goal of implementing log-in / log-out, including working with session and flash, writing custom routes, and writing custom controller methods.
I tried to highlight places where you could make use of partial views, controller filters, and model methods with in-line comments. Please let me know if you have any questions about these.
Since you did not have the opportunity to practice some of the new Rails tools on this project, on the current project (bEtsy), I encourage you to play close attention to testing the model with fixtures, model validations, and the custom routes and methods that enable to adding to cart and checkout features. Again, please let me know if you have any questions.
Overall Feedback | Criteria | yes/no |
---|---|---|
Green (Meets/Exceeds Standards) | 14+ in Functional Requirements: Manual Testing && 14+ in Code Review | |
Yellow (Approaches Standards) | 12+ in Functional Requirements: Manual Testing && 11+ in Code Review, or the instructor judges that this project needs special attention | |
Red (Not at Standard) | 0-10 in Code Review or 0-11 in Functional Reqs, or assignment is breaking/doesn’t run with less than 5 minutes of debugging, or the instructor judges that this project needs special attention | ✔️ |
Code Style Bonus Awards
Was the code particularly impressive in code style for any of these reasons (or more...?)
Quality | Yes? |
---|---|
Perfect Indentation | ✅ |
Descriptive/Readable | ✅ |
Logical/Organized | ✅ |
app/views/homepage/index.html.erb
Outdated
|
||
<h2>Top Albums</h2> | ||
<ul> | ||
<% top_ten = @albums.sample(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.
Consider moving this logic into a model method.
<% end %> | ||
</ul> | ||
|
||
<h2>Top Books</h2> |
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.
Note that this view code is almost identical to the code above for albums. You can use a loop or a partial view, combined with a model method that selects the work for a particular category, to DRY up this code.
app/views/homepage/index.html.erb
Outdated
<h1>Media Ranker</h1> | ||
|
||
<h2>Media Spotlight</h2> | ||
<% spotlight = @works.find_by(id: 1) %> |
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.
Good work having a place holder for this media spotlight.
app/controllers/users_controller.rb
Outdated
if ! user.save | ||
flash[:error] = "Unable to login" | ||
redirect_to root_path | ||
return | ||
end | ||
flash[:welcome] = "Welcome #{user.username}" | ||
else | ||
#Existing User | ||
flash[:welcome] = "Welcome back #{user.username}" | ||
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.
Good use of flash messages
get "/login", to: "users#login_form", as: "login" | ||
post "/login", to: "users#login" | ||
post "/logout", to: "users#logout", as: "logout" |
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.
Good work creating these custom routes.
@work = Work.find_by(id: params[:id]) | ||
|
||
if @work.nil? | ||
redirect_to works_path | ||
return | ||
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.
Consider adding this code to a controller filter like find_work
to DRY up your code.
create relation between votes and users/works
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.
Great job working through the logic for this project - It is now Green 👍
<td><%= link_to book.title, work_path(book) %></td> | ||
<td><%= book.creator %></td> | ||
<td><%= book.publication_year %></td> | ||
<td><%= link_to "Upvote", vote_path(book.id) %></td> |
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 link produces the error No route matches [GET] "/works/17/vote"
. The default method for link_to
is get, so you need to specify the method.
<td><%= link_to "Upvote", vote_path(book.id) %></td> | |
<td><%= link_to "Upvote", vote_path(book.id), method: :post %></td> |
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.
With this change, the upvote
button works!
flash[:message] = "Successfully created" | ||
redirect_to work_path(@work) | ||
else | ||
flash[:error] = "Failed to create new media" |
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.
To show the specifics of the failed validations, access @work.errors.messages. You can do this in your view or iterate through the messages here and store them in the flash
hash.
Work.all.order(vote_count: :desc).first | ||
end | ||
|
||
def self.top_ten_books |
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.
Consider using a single method for all categories that takes the category as a parameter to DRY up your code:self.top_ten(category)
. Then you can use the .find
method to get all works from that category, and sort them.
@@ -0,0 +1,41 @@ | |||
<% books = @works.where(category: "book") %> |
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 is a great place to make use of the top_ten
method from your model so you don't put logic in the view.
<% albums.each do |album | %> | ||
<tr> | ||
<td><%= album.vote_count %></td> | ||
<td><%= link_to album.title, work_path(album) %></td> | ||
<td><%= album.creator %></td> | ||
<td><%= album.publication_year %></td> | ||
<td><%= link_to "Upvote", vote_path(album.id) %></td> | ||
</tr> | ||
<% 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.
Note that you have three blocks of code that are almost identical. Consider how you can use a partial view with the local variable being the category or a loop to dry up this code.
@work = Work.find_by(id: params[:id]) | ||
|
||
if @work.nil? | ||
head :not_found | ||
return | ||
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.
Note this functionality is used in multiple methods. This is a great place for a controller filter find_work
@work = Work.find_by(id: params[:id]) | ||
|
||
if @work.nil? | ||
head :not_found |
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.
Consider adding redirect behavior rather than head :not_found
to redirect the user to a useful page.
description: this is work1 | ||
publication_year: 2020 | ||
category: album | ||
vote_count: 1 |
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.
Rather than adding a vote_count to the work fixture, it is best to rely on the relationship between works and votes, such that the way that a vote_count is increased is by a work having vote fixtures.
Media Ranker
Congratulations! You're submitting your assignment!
Comprehension Questions
session
andflash
? What is the difference between them?Assignment Submission: Media Ranker
Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.
Reflection
session
andflash
? What is the difference between them?