这是一段代码:
def update
@category = Category.find(params[:id])
if @category.update_attributes(params[:category], :as => :roles_update)
@category = Category.find[params[:id]]
render 'show', :notice => 'Category was successfully updated'
else
@categories = Category.all
render 'index'
end
end
执行上述操作时出错:
Couldn't find Category without an ID
但是参数dump中有类别id(= 1):
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"aFk+bcHKA3zwck1PgrNOwVvZfeXtsT57ywHGiB4odDY=",
"category"=>{"description"=>"audio/video",
"active"=>"1"},
"commit"=>"Update Category",
"id"=>"1"}
如果在IF循环中注释掉#@ category = Category.find [params [:id]],代码将不会出错。但是rspect给出了错误:ActiveRecord :: RecordNotFound:
有关此问题的任何建议吗?感谢
答案 0 :(得分:1)
@category = Category.find[params[:id]]
应该是:
@category = Category.find(params[:id])