我有一个有时可以工作,有时不能工作的表单,除了重启rails应用程序之外,我无法弄清楚两次之间发生了什么变化。目前它不起作用。
我的routes文件中有以下条目:
constraints :subdomain => 'my' do
namespace 'my', path: nil do
namespace 'author' do
resources :test_author do
resources :steps_author
[...]
end
end
end
end这里我感兴趣的特定路由是从rake routes生成的
my_author_test_author_steps_author GET /author/test_author/:test_author_id/steps_author/:id(.:format) my/author/steps_author#show {:subdomain=>"my"}
PUT /author/test_author/:test_author_id/steps_author/:id(.:format) my/author/steps_author#update {:subdomain=>"my"}
DELETE /author/test_author/:test_author_id/steps_author/:id(.:format) my/author/steps_author#destroy {:subdomain=>"my"}我打开的表单如下所示(使用简单的表单和引导程序):
<%= simple_form_for @step, :url => my_author_test_author_steps_author_path(@step), :html => { :class => 'form-horizontal' } do |f| %>有人能解释一下发生了什么吗?
更新
根据juanpastas的帮助,表单似乎呈现正确,但是Rails将请求解释为POST而不是PUT。不过,对于我的生活,我不知道为什么。
发布于 2013-05-04 20:40:35
需要在路由中传递完整的参数
<%= simple_form_for @step,
:url => my_author_test_author_steps_author_path(author, @step),
:html => { :class => 'form-horizontal' } do |f| %>在读完你的标题后,我看到你应该在/author/test_author/24/steps_author/上发帖,而不是最后一个数字。下面是什么:
<% url = !@step.persisted? ? '/author/test_author/24/steps_author/' : my_author_test_author_steps_author_path(author, @step) %>
<%= simple_form_for @step,
:url => url,
:html => { :class => 'form-horizontal' } do |f| %>我已经对路由进行了硬编码,因为我不确定您的路由助手名称。您可以运行rake routes来查找该帮助器。
https://stackoverflow.com/questions/16374257
复制相似问题