Skip to content

Amber Lynn - Edges | MediaRanker#40

Open
griffifam wants to merge 48 commits intoAda-C10:masterfrom
griffifam:master
Open

Amber Lynn - Edges | MediaRanker#40
griffifam wants to merge 48 commits intoAda-C10:masterfrom
griffifam:master

Conversation

@griffifam
Copy link

Media Ranker

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Describe a custom model method you wrote. self.show_by_vote(category) is a method in the work model that sorts all work based on their votes in and displays votes based on category. This is what I used to sort work by votes that kept much of the logic out of the view and kept view dry.
Describe how you approached testing that model method. What edge cases did you come up with? I created work fixtures and vote fixtures. I used a category to sort all the work by vote from that category stored them to a variable and iterated through the list checking to see if the current index element was greater than or equal to the element to the right of it (after it). If all elements followed this flow return true else false because a vote later in the array would have been higher than the one before it THUS the method did not sort correctly.
What are session and flash? What is the difference between them? Session and flash are ruby magic. A session is just a container that holds data for a given time. A flash is a message that displays after a specific action. Its typically used to validate actions.
Describe a controller filter you wrote. I used a controller filter to gather work the user is on. So before each action the work associated with current view was retrieved and stored to a variable.
What was one thing that you gained more clarity on through this assignment? How to write custom validations and how to use custom methods in the controller. I learned about .pluck and what it could be used for.
What is the Heroku URL of your deployed application? https://mediagalore.herokuapp.com/
Do you have any recommendations on how we could improve this project for the next cohort? Trouble shoot heroku.

…ulation of current work data into form. tested user model validations
…cation.html.erb to include how and where flash messages will render on page
@griffifam griffifam closed this Oct 15, 2018
@griffifam griffifam reopened this Oct 15, 2018
@tildeee
Copy link

tildeee commented Oct 26, 2018

Media Ranker

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene x
Comprehension questions x -- session and flash are not just Ruby magic ;) They're hash-like objects that hold data. Flash is a hash-like object that stores data for one request/response cycle.
General
Rails fundamentals (RESTful routing, use of named paths) x
Views are well-organized (DRY, use of semantic HTML, use of partials) Didn't use a partial for the nearly-identical edit and new forms for Works
Errors are reported to the user Didn't show me an error message when there was a problem making a new Work
Business logic lives in the models x
Models are thoroughly tested, including relations, validations and any custom logic x, nice work on validations and relations particularly
Wave 1 - Media
Splash page shows the three media categories x
Basic CRUD operations on media are present and functional Some unexpected behaviors on edit and delete (outlined below)
Wave 2 - Users and Votes
Users can log in and log out x, some unexpected behaviors on logging in (outlined below)
The ID of the current user is stored in the session x
A user cannot vote for the same media more than once x
All media lists are ordered by vote count x
Splash page contains a media spotlight x
Wave 3 - Users and Votes
Media pages contain lists of voting users x
Individual user pages and the user list are present x
Optional - Styling
Bootstrap is used appropriately in-progress
Look and feel is similar to the original in-progress
Overall

Hi Amber-Lynn! Good work on this project -- I think that there are a lot of really good clean parts of your code (a lot of use of Enumerable methods in clean ways!) and a few places that I think could get better.

In general, one of my biggest concerns is the variations from your project submission compared to the original. A lot of this project was around taking the original and trying to mimic it, but I saw some differences between them in regards to use flow.

Why do I need to make a new user on a separate form? In the original, if a user didn't exist at log-in, then the site would make a new user. In the submission, if the user doesn't exist at log-in, then I have to go to a new form to make a new user. Also, after editing a work, where should it go? In the original, after editing a work, then the site redirects you to the work detail page. In the submission, after editing a work, the site redirects you to the user page. Lastly, what should happen after you delete a work? In the original, after deleting a work, then the site redirects you to the home page. In the submission, after deleting a work, the site redirects you to the work detail page, which, because the work doesn't exist anymore, is broken!

My other concern with your code submission are the bits of code that seem to be unused, but still are here. In general, if code is unused, we'd prefer you delete it.

That being said, I think your project hits most of the learning goals-- the code that was there and worked was good. It mostly misses some things around partials, some weird areas of code/buggy code, and missing some alignment with mimicking the original site's user flow

has_many :votes
has_many :users, through: :votes

CATEGORIES = %w(movie book album)
Copy link

Choose a reason for hiding this comment

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

Nice constant variable!

validates :user_id, presence: true
validates :work_id, presence: true

validate :one_vote_per_user, on: :create
Copy link

Choose a reason for hiding this comment

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

Nice custom validation!


validates :title, presence: true, uniqueness: true
validates :creator, presence: true
validates :publication_year, presence: true, :numericality => {:less_than => Date.today.year, :greater_than => 1700}
Copy link

Choose a reason for hiding this comment

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

Nice adding this validation... But did the original site have this validation on it?


def self.show_by_vote(category)
Work.all.sort_by { |work| -work.votes.count }.select { |work| work.category == category}
end
Copy link

Choose a reason for hiding this comment

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

Really nice method! Nice use of enumerable methods to take this logic and make it concise

<div class="list-inline">
<div class="p-3 mb-2 bg-info text-white"><%= link_to "View all media", works_path, class: "all_works-link" %></div>
<div class="text-white"><%= link_to "Add a new work", new_work_path, class: "new_work-link" %></div>
<div cclass="text-white"><%= link_to "View all users", users_path, class: "new_work-link" %></div>
Copy link

Choose a reason for hiding this comment

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

Typo! cclass?

<%= yield %>
</main>

<footer>Footer Info</footer>
Copy link

Choose a reason for hiding this comment

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

Was there a footer on the original site?

@@ -0,0 +1,37 @@
<div class="container">
Copy link

Choose a reason for hiding this comment

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

When is this view used?

locals: {
model: @work
}
%>
Copy link

Choose a reason for hiding this comment

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

Does this form need to also render the partial of itself?

<%= f.select :category, Work::CATEGORIES %>
<%= f.submit action_type, class: "work btn" %>
<% end %>
</div>
Copy link

Choose a reason for hiding this comment

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

You have an end on line 23 that ends the form_with block that started on line seven... And you have a div that starts on line 11 and ends on line 24. These aren't neatly nested with each other -- you should be mindful that your end should be outside of anything that it includes fully, otherwise it isn't proper syntax and you'll get negative side-effects

<%= f.select :category, Work::CATEGORIES %>
<%= f.submit action_name, class: "work btn" %>
<% end %>
</div>
Copy link

Choose a reason for hiding this comment

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

You end up having essentially a form duplicate to the edit form... Why didn't you use the partial? Would that have also worked?

post '/works/:id/upvote', to: 'works#upvote', as: 'upvote'

resources :users, except: [:edit, :update, :destroy] do
end
Copy link

Choose a reason for hiding this comment

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

if there's no nesting, do you need the do ... end bit?


post '/sessions/logout', to: 'sessions#logout', as: 'logout'

# get '/works', to: 'works#index', as: 'all_works'
Copy link

Choose a reason for hiding this comment

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

Feel free to delete your comments before submission!

describe "self.show_by_vote(category)" do
it "returns sorted movies in descending order based on votes" do
@books = Work.show_by_vote("book")
book_result = @books.length.times do |i|
Copy link

Choose a reason for hiding this comment

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

Since you don't use the variable book_result, you're probably okay to just make the above line @books.length.times do |i| without the variable assignment so that you don't have any unused variables

works = Work.all

result = works.each do |work|
@top_work.votes.count >= work.votes.count
Copy link

Choose a reason for hiding this comment

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

Doesn't this need to be in an if?


result = works.each do |work|
@top_work.votes.count >= work.votes.count
return true
Copy link

Choose a reason for hiding this comment

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

Should this "return true"? return will make the loop stop after one iteration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants