我得到这个错误:为什么我得到这个错误?
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