Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Doing away with song ratings

  • Loading branch information...
commit a053932ca19301cee1ce762fab33bd9ab5057aa4 1 parent 5b633b6
@alexcrichton authored
View
50 app/assets/stylesheets/application.scss
@@ -123,56 +123,6 @@ a {
width: 400px;
}
-.song .ratings {
- float: left;
- overflow: auto;
- width: 65px;
- margin: 10px 0 0 0;
-
- .rating {
- float: left;
- margin: 0;
- padding: 3px;
-
- width: 23px;
- border: 1px solid black;
- }
-
- ul {
- list-style: none;
- float: left;
- width: 20px;
- padding: 0;
- margin: 0 auto;
- }
-
- li {
- margin: 0;
- display: block;
- font-size: 10px;
- border: 1px solid black;
- }
-
- ul.user {
- li {
- cursor: pointer;
- }
- li.selected {
- background: blue;
- }
- }
-
- ul.overall li.selected {
- background: green;
- }
-
- .score {
- text-align: center;
- display: inline-block;
- width: 100%;
- }
-}
-
.song .add {
position: absolute;
}
View
22 app/controllers/songs_controller.rb
@@ -11,8 +11,6 @@ def index
if params[:order] == 'play_count'
@songs = top_level.order_by :play_count.desc
- elsif params[:order] == 'rating'
- @songs = top_level.order_by :rating.desc
else
@songs = top_level.order_by :title.asc
end
@@ -45,26 +43,6 @@ def edit
respond_with @song
end
- # def rate
- # scope = @song.ratings.by current_user
- #
- # if @rating = scope.first
- # @rating.update_attributes! params[:rating]
- # else
- # @rating = scope.build params[:rating]
- # @rating.user = current_user
- # @rating.song = @song
- # @rating.save! # we expect this to work
- # end
- #
- # @song.reload # Our rating has changed
- #
- # Pusher['song'].trigger 'rating', :song_id => @song.id,
- # :rating => @song.rating
- #
- # respond_with @song
- # end
-
def update
@song.update_attributes params[:song]
View
11 app/models/song.rb
@@ -4,7 +4,6 @@ class Song
field :title
field :album_name
field :custom_set, :type => Boolean
- field :rating, :type => Float, :default => 0.0
field :play_count, :type => Integer, :default => 0
mount_uploader :audio, SongUploader
@@ -13,7 +12,6 @@ class Song
belongs_to :album
belongs_to :artist
- embeds_many :ratings, :class_name => 'Song::Rating'
validates_presence_of :title, :artist
validates_uniqueness_of :title, :scope => :artist_id,
@@ -34,15 +32,6 @@ class Song
end
}
- def update_rating
- if ratings.size == 0
- self[:rating] = 0.0
- else
- self[:rating] = ratings.map(&:score).sum.to_f / ratings.size
- end
- save!
- end
-
protected
def ensure_artist_and_album
View
22 app/models/song/rating.rb
@@ -1,22 +0,0 @@
-class Song::Rating
- include Mongoid::Document
-
- field :score, :type => Integer
-
- embedded_in :song
- belongs_to :user
-
- validates_presence_of :song, :user
-
- after_create :update_song_rating
- after_update :update_song_rating
- after_destroy :update_song_rating
-
- scope :for, lambda{ |song| where(:song_id => song.id) }
- scope :by, lambda{ |user| where(:user => user) }
-
- def update_song_rating
- song.update_rating
- end
-
-end
View
1  app/views/layouts/_topnav.html.erb
@@ -19,7 +19,6 @@
<%= link_to 'Songs', songs_path %>
<ul>
<li><%= link_to 'Play Count', songs_path(:order => 'play_count') %></li>
- <li><%= link_to 'Rating', songs_path(:order => 'rating') %></li>
<li><%= link_to 'Upload', new_song_path %></li>
<li><%= link_to 'Search', search_songs_path %></li>
</ul>
View
28 app/views/songs/_song.html.erb
@@ -26,35 +26,7 @@
</p>
</div>
- <div class='ratings' remote="<%= url_for [:rate, song] %>">
- <div class='rating'>
- <ul class='overall' data-rating="<%= number_to_percentage song.rating %>">
- <% (1..10).each do |score| %>
- <li<%= raw(' class="selected"') if score > 10 - song.rating %>>
- &nbsp;
- </li>
- <% end %>
- </ul>
- <span class='score overall'><%= song.rating.to_i %></span>
- </div>
- <div class='rating'>
- <% rating = song.ratings.by(current_user).first.try(:score) || 0 %>
- <ul class='user' data-rating="<%= rating %>">
- <% (1..10).each do |score| %>
- <li<%= raw(' class="selected"') if score > 10 - rating %>>
- &nbsp;
- </li>
- <% end %>
- </ul>
- <span class='score user'><%= rating %></span>
- </div>
- </div>
-
<div class='links'>
- <% if defined?(item) %>
- <p>Queued by: <%= item.user.name if item.user %></p>
- <% end %>
-
<p>
<%= link_to '[download]', song_url(song, :format => 'mp3') %>
View
2  config/routes.rb
@@ -15,11 +15,9 @@
resources :songs do
get :search, :on => :collection
- put :rate, :on => :member
end
get 'fargo/search'
- # post 'fargo/download'
post 'pusher/auth' => 'users#pusher_auth'
namespace :radio do

0 comments on commit a053932

Please sign in to comment.
Something went wrong with that request. Please try again.