【发布时间】:2009-11-10 20:38:23
【问题描述】:
我正在尝试编辑一个表单,路径是控制器/id/用于编辑的操作,例如
人/124321/编辑
我正在尝试使用此代码将此表单提交给更新操作:
<% form_for :probe, @probe, :action => "update" do |f| %>
...
...
...
<%= submit_tag 'Submit' %>
<% end %>
当我点击提交时,它给了我一个错误提示
未知动作。 未对 (id) 做出任何响应。
编辑
我的路线中唯一为探测指定的是 map.resources :probes
当我生成控制器时,RoR 只是自己做了 people/124321/edit。
Rake 路线显示了这一点
probes GET /probes(.:format) {:controller=>"probes", :action=>"index"}
POST /probes(.:format) {:controller=>"probes", :action=>"create"}
new_probe GET /probes/new(.:format) {:controller=>"probes", :action=>"new"}
edit_probe GET /probes/:id/edit(.:format) {:controller=>"probes",action=>"edit"}
GET /probes/:id(.:format) {:controller=>"probes", :action=>"show"}
PUT /probes/:id(.:format) {:controller=>"probes", :action=>"update"}
DELETE /probes/:id(.:format) {:controller=>"probes", :action=>"destroy"}
编辑 2 探针控制器
def edit
@probe = Probe.find(params[:id])
end
def update
@probe = Probe.find(params[:id])
debugger
if @probe.update_attributes(params[:probe])
flash[:notice] = "Successfully updated probe."
redirect_to probes_path
else
render :action => 'edit'
end
end
【问题讨论】:
-
你能准确地发布你的路线吗?
-
应该是controller/action/id...对吧?还是我错过了什么?
-
有时查看生成的 HTML 有助于了解问题出在控制器还是视图上。 HTML 应明确包含 /people/
/edit.
标签: ruby-on-rails