-
Notifications
You must be signed in to change notification settings - Fork 42
Ampers - Mariko A. - Media Ranker #39
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
base: master
Are you sure you want to change the base?
Conversation
…s and works, added foreign keys to votes
…ace for top media, and top ten for each category
…ks show pages. Oh and nested routes for votes create.
…er is informed of what errors occured based on validations.
…ted user show view, probably other shit too.
…ique to category. Users must be logged in to vote.
Media RankerWhat We're Looking For
|
|
|
||
| root 'welcomes#index' | ||
|
|
||
| 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.
Do you need all the routes for users?
| redirect_to work_path(@work.id) | ||
| else | ||
| flash.now[:alert] = @work.errors | ||
| render :new |
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 set @valid_categories before trying to render :new
| <% flash[:alert].each do |field, message| %> | ||
| <li> | ||
| <strong><%= field %>: </strong> | ||
| <%= message.join('') %> |
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 join is causing works error messages to crash the site.
| session[:user_id] = @user.id | ||
| flash[:success] = "Welcome back #{@user.user_name}" | ||
| else | ||
| @user = User.create user_name: params[:user][:user_name] |
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 check to verify that create worked! I tried to log in with a blank username and got a "welcome" message! :p
| belongs_to :user | ||
| belongs_to :work | ||
|
|
||
| validates :user, uniqueness: {scope: :work, message: "You have already voted for this title."} |
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.
🥇
|
|
||
| def self.ordered_works(category) | ||
| works = Work.all.where(category: category).to_a | ||
| return works.sort_by {|work| -work.vote_count} |
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.
👍
| class Work < ApplicationRecord | ||
| has_many :votes | ||
|
|
||
| validates :category, presence: {message: "Must provide a category"} |
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 would also ensure that the category can only be, "album", "book" or "movie"
| end | ||
| end | ||
|
|
||
| describe 'ordered_works' do |
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 also need to test when:
- There are no works
- There are no votes
- One category has no votes.
| # | ||
| describe 'media_spotlight' do | ||
| it "returns the work with the higest vote count" do | ||
| Work.media_spotlight.must_equal works(:work_one) |
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.
Again, what happens when there are no votes?
Media Ranker
Congratulations! You're submitting your assignment!
Comprehension Questions
sessionandflash? What is the difference between them?