なぜ私は今これを手に入れたのですか?新しいユーザーが曲をアップロードし、投票に行ったところ、次の結果が得られました: (これは、ステージング ブランチを作成した後に発生しました)
ActiveRecord::RecordNotFound (Couldn't find Song with id=attention-let-me-go-remix):
2013-08-14T06:11:31.740608+00:00 app[web.1]: app/controllers/songs_controller.rb:13:in `vote_for'
曲のコントローラーのスニピット
class SongsController < ApplicationController
before_filter :authenticate_user!, only: [:new, :create ,:edit, :update, :destroy, :vote_for_song]
before_action :set_song, only: [:show, :edit, :update, :destroy, :vote_for_song]
def extract_video
@song = Song.find(params[:id])
@song.YouTubeAddy.extract_video_id
end
def vote_for
@song = Song.find(params[:id])
current_user.vote_for(@song)
@song.plusminus = @song.votes_for
@song.save
respond_to do |format|
format.js { render 'update_votes' }
end
end
def vote_against
@song = Song.find(params[:id])
current_user.vote_against(@song)
respond_to do |format|
format.js { render 'update_votes' }
end
end
def new_songs
@songs = Song.order("id DESC").paginate(:page => params[:page], :per_page => 15)
get_last_song
end
# GET /Songs
# GET /Songs.json
def index
if params[:query].present?
@songs = Song.search(params)
get_last_song
elsif params[:genre]
@songs = Song.tagged_with(params[:genre]).paginate(:page => params[:page], :per_page => 15)
get_last_song
else
@songs = Song.order('id').order('plusminus desc nulls last').paginate(:page => params[:page], :per_page => 15)
#@songs = Song.tally.paginate(:page => params[:page], :per_page => 15)
get_last_song
end
end
def get_last_song
if params[:page].nil?
@last_song = 0
else
@last_song = 15 * (params[:page].to_i - 1)
end
end
# GET /Songs/1
# GET /Songs/1.json
def show
@comment = Comment.new(song: @song)
@video_tag = YouTubeAddy.extract_video_id(@song.url)
end
# GET /Songs/new
def new
@song = Song.new
end
# GET /Songs/1/edit
def edit
end
# POST /Songs
# POST /Songs.json
def create
@song = Song.new(song_params)
@song.user = current_user
respond_to do |format|
if @song.save
format.html { redirect_to @song, notice: 'Song was successfully created.' }
format.json { render action: 'show', status: :created, location: @song }
else
format.html { render action: 'new' }
format.json { render json: @song.errors, status: :unprocessable_entity }
end
end
end
スキーマ スニピット
create_table "songs", force: true do |t|
t.string "title"
t.string "artist"
t.text "url"
t.string "track_file_name"
t.string "track_content_type"
t.integer "track_file_size"
t.datetime "track_updated_at"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "plusminus"
t.string "slug"
end