2012-07-17 103 views
0

這是工作,但現在我打電話時的update_attributes,提示以下錯誤:Rails的 - 現在的update_attributes正在越來越未定義的方法錯誤

NoMethodError in SongsController#update 

undefined method `name' for nil:NilClass 
Rails.root: C:/Sites/music3 

Application Trace | Framework Trace | Full Trace 
app/controllers/songs_controller.rb:164:in `update' 

什麼是困惑我的是,我的@song對象不有它的「名字」。 (請參閱下面的架構),但藝術家的確如此。歌曲和藝術家通過多對多的關係相關聯。看起來像update_attributes正在嘗試更新藝術家對象?沒想到它應該這樣做。真的不知道這裏有什麼幫助將不勝感激。

謝謝,

Song Controller 
def update 
    @artist = Artist.find(params[:artist_id]) 
    authorize! :update, @artist 
    @song = Song.find(params[:form_song_id]) 
    @song.artists << @artist 
    @s3_test = params[:s3_name] 

    @song.update_attributes(params[:song]) #causing the error 
end 

架構

create_table "artists", :force => true do |t| 
    t.string "name" 
    t.string "city" 
    t.string "province" 
    t.string "country" 
    t.text  "influence" 
    t.text  "bio" 
    t.text  "contact_info" 
    t.date  "date_founded" 
    t.date  "created_date" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    t.string "url_slug" 
    t.string "pay_pal" 
    t.string "image" 
    end 

    create_table "songs", :force => true do |t| 
    t.string "song_name" 
    t.string "song_artist" 
    t.string "song_contribute_artist" 
    t.string "song_written" 
    t.string "song_licence_type" 
    t.string "song_url_slug" 
    t.date  "song_licence_date" 
    t.integer "song_plays" 
    t.text  "lyrics" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    t.string "s3_name" 
    t.string "download_link" 
    t.string "torrent_link" 
    t.string "s3_id" 
    t.integer "s_a_id" 
    end 

例PARAMS。

{"utf8"=>"âœ「", 
"_method"=>"put", 

"song"=>{"s3_name"=>#<ActionDispatch::Http::UploadedFile:0x260e908 @original_filename="done good (final final).mp3", 
@content_type="audio/mp3", 
@headers="Content-Disposition: form-data; name=\"song[s3_name]\"; filename=\"done good (final final).mp3\"\r\nContent-Type: audio/mp3\r\n", 
@tempfile=#<File:C:/Users/Ted/AppData/Local/Temp/RackMultipart20120716-1600-ohtooj>>, 
"song_name"=>"Done Good", 
"song_artist"=>"Grimes", 
"song_contribute_artist"=>"", 
"song_written"=>"Ted Kennedy", 
"song_licence_type"=>"copywrite", 
"song_licence_date(1i)"=>"2012", 
"song_licence_date(2i)"=>"7", 
"song_licence_date(3i)"=>"17", 
"song_plays"=>"", 
"song_url_slug"=>"", 
"lyrics"=>"None"}, 
"commit"=>"Upload", 
"artist_id"=>"1", 
"form_song_id"=>"5", 
"id"=>"create"} 
+0

嘗試運行'軌C'然後'Song.find(5)' – 2012-07-17 05:05:47

回答

0

試試這個,因爲那些不在歌類中。

params[:song].delete("@content_type") 
params[:song].delete("@tempfile") 
params[:song].delete("@headers") 
+1

那些被用來將歌曲文件上傳到AWS後來在更新。我現在已經離開了我的計劃,但是我會在下午晚些時候回家後告訴你,讓他們看看他們是否在引發錯誤。我也將添加其餘的更新。感謝您及時的回覆! – therealtedkennedy 2012-07-17 13:47:19

+1

工作。謝謝!完全是那些。結束時只需在amazon上傳後用params [:song] .delete:s3_name刪除s3_name(包含content_type,tempfile和headers)。 – therealtedkennedy 2012-07-18 01:42:46

相關問題