Rails 3 路由错误 [英] Rails 3 Routing Error

查看:48
本文介绍了Rails 3 路由错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我昨天有这个工作,我不知道我做了什么来破坏它.

I had this working yesterday, I don't know what I did to break it.

以下是 RESTful 控制器的路由:

Here are the routes for a RESTful controller:

brand_responsibilities    GET    /brands/:brand_id/responsibilities(.:format)          {:action=>"index", :controller=>"responsibilities"}
brand_responsibilities    POST   /brands/:brand_id/responsibilities(.:format)          {:action=>"create", :controller=>"responsibilities"}
new_brand_responsibility  GET    /brands/:brand_id/responsibilities/new(.:format)      {:action=>"new", :controller=>"responsibilities"}
edit_brand_responsibility GET    /brands/:brand_id/responsibilities/:id/edit(.:format) {:action=>"edit", :controller=>"responsibilities"}
brand_responsibility      GET    /brands/:brand_id/responsibilities/:id(.:format)      {:action=>"show", :controller=>"responsibilities"}
brand_responsibility      PUT    /brands/:brand_id/responsibilities/:id(.:format)      {:action=>"update", :controller=>"responsibilities"}
brand_responsibility      DELETE /brands/:brand_id/responsibilities/:id(.:format)      {:action=>"destroy", :controller=>"responsibilities"}

我的表单如下所示:

<%= form_for :responsibility, :remote => true do |f| %>
    <%= f.hidden_field :access_request_id, :value => ar.id %>
    <%= f.hidden_field :user_id, :value => user.id %>
    <%= f.hidden_field :brand_id, :value => @brand.id %>
    <%= f.submit %>
<% end %>

但我现在收到一条 404 并显示此日志消息:

But I get a 404 now with this log message:

Started POST "/brands/30/responsibilities" for 127.0.0.1 at Tue Oct 26 10:47:17 -0400 2010

ActionController::RoutingError (No route matches "/brands/30/responsibilities"):

看起来路线确实适合我!我错过了什么?

It sure looks like the route matches to me! What am I missing?

更新:我也在控制台中尝试过:

Update: I also tried this in the console:

rs.recognize_path '/brands/30/responsibilities', :method => :post

响应是:

=> {:controller=>"responsibilities", :brand_id=>"30", :action=>"create"}

我的交易是什么?

更新 #2:

我找到了原因,虽然我不知道这是什么原因.我有另一个领域:

I found the cause, though I don't know why it's the cause. I have another field:

<%= button_to "Deny", brand_responsibilities_path(@brand, :ar => ar), :remote => true, :method => :delete %>

我在表单中包含的内容.为了简洁起见,我之前省略了它,因为我认为它并不重要.我知道这是个坏主意.

That I was including in the form. I left it out for brevity's sake before because I didn't think it was important. I see that was a bad idea.

有谁知道为什么表单中的那一行会导致奇怪的路由错误?

Does anybody know why the presence of that line in the form causes the weird routing error?

推荐答案

看来我是个白痴.

遗漏那条关键信息是个坏主意.在表单中使用 button_to 是一个禁忌,它会在表单中创建一个表单.

Leaving out that crucial piece of information was a bad idea. Having a button_to within a form is a no-no, it creates a form within a form.

菜鸟错误.太糟糕了,我已经这样做了很长时间.给评论者点赞,抱歉浪费了您宝贵的时间.

Rookie mistake. Too bad I've been doing this for a long time. Upvotes to the commenters, sorry for wasting your valuable time.

这篇关于Rails 3 路由错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆