开发者

ActionController::MethodNotAllowed

开发者 https://www.devze.com 2022-12-28 20:59 出处:网络
I have a rails model called \'audioclip\'. 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

I have a rails model called 'audioclip'. 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.

Going to /audioclips/new_record doesn't work because it takes 'new_record' as if it was an id. Instead of changing this, I was trying to ju开发者_高级运维st create '/record_clip' and '/upload_clip' paths.

So in my routes.db I have:

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

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


Yes, your two routes are conflicting with your mapped resource (the map.resources => :audioclips bit).

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:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消