我得到這個錯誤:爲什麼我得到這個錯誤?
ActiveRecord::RecordNotFound (Couldn't find Video without an ID):
app/controllers/videos_controller.rb:52:in `topic_update'
它指的是這個動作在我的視頻控制器:
def topic_update
@video = Video.find(params[:id])
respond_to do |format|
if @video.update_attributes(params[:video])
format.html { redirect_to(@video) }
format.js
else
format.html { render :action => "edit" }
end
end
end
錯誤是這種形式拋出後發送一個PUT請求:
<%= form_for @video, :url => {:action => "topic_update"}, :remote => true do |f| %>
<div class="field">
<%= f.text_field :topic_names, :class => "topic_field" %>
</div>
<%= f.submit "Add Topic", :id => 'topic_submit' %>
<% end %>
這是根據我的日誌發生的情況:
Started PUT "/topic/update.js" for 127.0.0.1 at Mon Apr 11 00:12:19 -0700 2011
Processing by VideosController#topic_update as JS
Parameters: {"video"=>{"topic_names"=>"eedefva"}}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 57 LIMIT 1
我有這個在我的routes.rb文件:
resources :videos
match '/topic/update' => "videos#topic_update"
我該如何解決這個問題?如果我將表單更改爲':url => {:action =>「update」}',那麼它會突然生效......但是我想要轉到topic_update方法 – 2011-04-11 04:26:15
您沒有將'id'參數傳入請求。檢查你的route.config文件。檢查網址以查看您是否將id作爲參數傳遞。 – 2011-04-11 04:27:14