首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有与[POST]匹配的路由"/author/test_author/24/steps_author/13“

没有与[POST]匹配的路由"/author/test_author/24/steps_author/13“
EN

Stack Overflow用户
提问于 2013-05-04 20:23:25
回答 1查看 59关注 0票数 0

我有一个有时可以工作,有时不能工作的表单,除了重启rails应用程序之外,我无法弄清楚两次之间发生了什么变化。目前它不起作用。

我的routes文件中有以下条目:

代码语言:javascript
复制
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生成的

代码语言:javascript
复制
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"}

我打开的表单如下所示(使用简单的表单和引导程序):

代码语言:javascript
复制
<%= simple_form_for @step, :url => my_author_test_author_steps_author_path(@step), :html => { :class => 'form-horizontal' } do |f| %>

有人能解释一下发生了什么吗?

更新

根据juanpastas的帮助,表单似乎呈现正确,但是Rails将请求解释为POST而不是PUT。不过,对于我的生活,我不知道为什么。

EN

回答 1

Stack Overflow用户

发布于 2013-05-04 20:40:35

需要在路由中传递完整的参数

代码语言:javascript
复制
<%= 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/上发帖,而不是最后一个数字。下面是什么:

代码语言:javascript
复制
<% 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来查找该帮助器。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16374257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档