我是一名 Rails 初学者,现在我按照指南创建一个测试项目,如下所示:
admin_controller.rb
def blogEdit
@btnName = "更新"
@submitURL = "blogUpdate"
@blog=Blog.find(params[:id])
end
def blogUpdate
@blog=Blog.find(params[:id])
@blog.update(params[:blog])
redirect_to "/admin/blogList"
end
blogEdit.slim
= render "blogForm"
_blogForm.slim
=form_for :blog,url:{action: @submitURL} do |f|
=f.label :title ,"标题"
=f.text_field :title
=f.label :body ,"内容"
=f.text_area :body,rows:10,style:'width:500px;'
=f.label :author ,"作者"
=f.text_field :author
=f.hidden_field :id
=f.submit @btnName,class:'btn'
但是当我更新博客时,我得到了错误:
Couldn't find Blog without an ID
Rails.root: /home/hxh/share/ruby/myblog
Application Trace | Framework Trace | Full Trace
app/controllers/admin_controller.rb:28:in `blogUpdate'
Request
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"3SBp+xSft8SzA5poczxNSU1zKReO2OpZQqgESn6ZURs=",
"blog"=>{"title"=>"违法的",
"body"=>"的说法都是",
"author"=>"似懂非懂",
"id"=>"2"},
“提交”=>“更新”}
所以它表明我没有得到params[:id]
@blog=Blog.find(params[:id])
我已经按照指南进行操作,为什么我得到了结果?