ActionController::MethodNotAllowed (Only get and post requests are allowed.)

I have a restful controller that when a uri of items/1/edit is
displayed and then saved, I get that message.

The model is InventroyItem and the controller is
InventroyItemsController.
The routes.rb contains map.resources inventory_items
The form uses partials and contains:

<% form_for(:inventory_item, :url =>
inventory_item_path(@inventoryitem), :html => { :method => :put }) do |
f> %>
   <%= render :partial => 'inventory_item', :locals => {:f => f} %>
<% end %>

Any ideas?

Donald French

bump.

Any ideas, anybody?

Don French

Did you ever solve this? I have the same problem and I have no idea
what's causing it.

Don French wrote:

I have a restful controller that when a uri of items/1/edit is
displayed and then saved, I get that message.

The model is InventroyItem and the controller is
InventroyItemsController.
The routes.rb contains map.resources inventory_items
The form uses partials and contains:

<% form_for(:inventory_item, :url =>
inventory_item_path(@inventoryitem), :html => { :method => :put }) do |
f> %>
   <%= render :partial => 'inventory_item', :locals => {:f => f} %>
<% end %>

Any ideas?

Donald French

Any solution.... I have a similar problem. But the error i get is

"ActionController::MethodNotAllowed Only get requests are allowed."

I had this problem a couple of months ago.... and found a solution. But
for the life of me can't remember what it was and where i saved it.

Ok.... I solved the problem i was having. I had a typo in my form_for

this....

<% form_for @profile, :url=>person_profile_url, :html=>{:method=>:put}
do |f| %>

when it should have been this

<% form_for :profile, @profile, :url=>person_profile_url,
:html=>{:method=>:put} do |f| %>

Hope this helps someone.

Which version of Mongrel do you have?

I am using 1.1.5, which I think is the latest.

Hey I found something else...

It seems like when this bugs occurs (ie: when using an .RJS extension),
there is a double request made to (or by) the webserver. But at the
second request, all the form arguments are empty, which seems to cause
the _method=delete argument to be lost and raises the MethodNotAllowed
exception.

After erasing the log file and rebooting, here's the log of the error:

Processing ChoicesController#destroy (for 127.0.0.1 at 2008-08-06
21:53:14) [DELETE]
  Session ID:
BAh7BzoMY3NyZl9pZCIlNmEwODc0ZmUyM2I0OTlmMDI4ODdjZDYxZWU4NWEy
NzQiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh
c2h7AAY6CkB1c2VkewA=--d44a044b8b3a01495e7459675bdd89ff41d62303
  Parameters: {"question_id"=>"8113", "_method"=>"delete",
"action"=>"destroy", "survey_id"=>"344", "id"=>"35843",
"controller"=>"admin/choices"}
Rendering admin/choices/destroy
Completed in 0.01925 (51 reqs/sec) | Rendering: 0.01007 (52%) | DB:
0.00092 (4%) | 200 OK
[http://localhost/admin/surveys/344/questions/8113/choices/35843]

Processing ApplicationController#index (for 127.0.0.1 at 2008-08-06
21:53:31) [POST]
  Session ID:
BAh7BzoMY3NyZl9pZCIlNmEwODc0ZmUyM2I0OTlmMDI4ODdjZDYxZWU4NWEy
NzQiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh
c2h7AAY6CkB1c2VkewA=--d44a044b8b3a01495e7459675bdd89ff41d62303
  Parameters: {}

ActionController::MethodNotAllowed (Only get, put, and delete requests
are allowed.):
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/routing/recognition_optimisation.rb:65:in
`recognize_path'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/routing/route_set.rb:384:in
`recognize'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:148:in
`handle_request'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:107:in
`dispatch'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in
`synchronize'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in
`dispatch'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:120:in
`dispatch_cgi'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:35:in
`dispatch'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:76:in
`process'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:74:in
`synchronize'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:74:in
`process'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in
`process_client'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in
`each'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in
`process_client'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
`initialize'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
`new'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in
`initialize'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in
`new'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:282:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in
`each'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:128:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/command.rb:212:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:502:in
`load'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:502:in
`load'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in
`new_constants_in'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:502:in
`load'
    /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/servers/mongrel.rb:64
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in
`require'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in
`new_constants_in'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in
`require'
    /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/server.rb:39
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
    ./script/server:3

Rendering
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/templates/rescues/layout.erb
(method_not_allowed)

Same problem.. running on windows XP 64

David

The method used is by default POST. You can also specify GET or you can
simulate PUT or DELETE over POST. All specified with options[:method]

link_to_remote "Destroy", :url => edit_person_url(@person), :method =>
:get