简体   繁体   English

ActionController :: MethodNotAllowed

[英]ActionController::MethodNotAllowed

I have a rails model called 'audioclip'. 我有一个名为“ audioclip”的rails模型。 I orginally created a scaffold with a 'new' action, which I replaced with 'new_record' and 'new_upload', becasue there are two ways to attach audio to this model. 我最初用“ new”动作创建了一个脚手架,将其替换为“ new_record”和“ new_upload”,因为有两种方法可以将音频附加到该模型。

Going to /audioclips/new_record doesn't work because it takes 'new_record' as if it was an id. 转到/ audioclips / new_record无效,因为它将'new_record'当作是id一样。 Instead of changing this, I was trying to just create '/record_clip' and '/upload_clip' paths. 我没有更改它,而是尝试仅创建'/ record_clip'和'/ upload_clip'路径。

So in my routes.db I have: 所以在我的routes.db中,我有:

map.record_clip '/record_clip', :controller => 'audioclips', :action => 'new_record'
map.upload_clip '/upload_clip', :controller => 'audioclips', :action => 'new_upload'

When I navigate to /record_clip, I get 当我导航到/ record_clip时,我得到

ActionController::MethodNotAllowed
Only get, head, post, put, and delete requests are allowed.

I'm not extremely familiar with the inner-workings of routing yet. 我对路由的内部工作还不是很熟悉。 What is the problem here? 这里有什么问题? (If it helps, I have these two statements above map.resources => :audioclips (如果有帮助,我 map.resources =>:audioclips 上面有这两个语句

Yes, your two routes are conflicting with your mapped resource (the map.resources => :audioclips bit). 是的,您的两条路线与您的映射资源冲突( map.resources => :audioclips位)。

If you want to continue using resources, I suggest you change that line to: 如果您想继续使用资源,建议您将该行更改为:

map.resources => :audioclips,
                 :new => { 
                    :new_record_clip => :post,
                    :new_upload_clip => :post }

If you want some more information, the Rails guide is incredibly helpful on this topic: 如果您需要更多信息,Rails指南在以下主题方面会非常有用:

http://guides.rubyonrails.org/routing.html#adding-more-restful-actions http://guides.rubyonrails.org/routing.html#adding-more-restful-actions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM