Jun 17
Rails Error: ActionController::MethodNotAllowed
I ran into this error in Rails today:
Only get, head, post, put, and delete requests are allowed.With the trace ending on this line:
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/routing/recognition_optimisation.rb:65:in `recognize_path'
Turns out I had two versions of rails installed and my application was looking for the wrong version. I had to go into my application folder and edit config/environment.rb and changed line 8 from:
RAILS_GEM_VERSION = '2.1.0' unless defined? RAILS_GEM_VERSIONto:
RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
Just in case, you know, you run into a similar problem.
9 Comments so far
Leave a comment







You mean you had two versions of Rails, not Ruby… right?
Yes. I blame this typo on alliteration.
Just update your mongrel version to 1.15 and the problem is fixed.
gem update mongrel
I already had mongrel 1.1.5 installed and I still get this issue. As far as having to revert the application from a 2.1 Rails app to a 2.0.2 Rails app, that only tells us that it’s an issue with 2.1 which needs fixing.
Anybody else have this issue?
I was having this issue as well. I had this route in routes.rb:
map.connect ‘/:page’, :controller => ‘theme’, :action => ‘view’, :defaults => { :page => ‘index’ }
In script/console, running rs.recognize_path on any proper route would work, and browsing to http://localhost:3000/ would render as well, but browsing to http://localhost:3000/anything-else would cause that MethodNotAllowed error.
Updating Mongrel fixed it for me, so I can’t really say what the issue was.
Restarting the server fixed it for me.
I already had Mongrel 1.1.5, downgrading Rails wasn’t an option and other solution suggestions like changing routes etc. didn’t help.
Nevertheless this seems to be a route caching problem in Rails 2.1.0.
FYI,
I’ve been getting this (minus the head) on my facebook apps. I changed the request_method_with_facebooker method which used the facebook parameter fb_sig_request_method to mask the POST FB makes to a get — needed to do the same thing for the HEAD as well.
Hopefully that’ll help someone else too.
[…] be nice to know how widespread this problem is. This link talks about this same issue in the comments. The main post is a little confused […]
I had the same problem too, but it turned out that I had not not mapped my resources properly.
map.resource ‘/your_controller’
fixed this just fine