Forum: Ruby on Rails ActionController::MethodNotAllowed: Only get, put, and delete requests are allowed.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9c7d80ebc20ab8994e51b9f7518909ae?d=identicon&s=25 Luca G. Soave (lgs)
on 2008-10-11 19:18
(Received via mailing list)
Hi all,

I'd need some help with a Subject already appeared here,  anyway I "re-
post" with same title cause reading the old threads didn't help me.

I get a tipical restful routes mismatching :

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

but after several try & errors, I don't actually understand what's
wrong with it, here are salients bits ...

rails -v :
                 Rails 2.1.1

rake routes :

                 create_services POST   /services/
create
{:action=>"create", :controller=>"services"}
                 formatted_create_services POST   /services/
create.:format
{:action=>"create", :controller=>"services"}

the patrial which get in error ( _delicious.html.erb ):

<% form_for @service.url, create_services_path do |f| %>
  <%= f.error_messages %>
  <p>
    <%= image_tag("/images/sites_icons/delicious.png") -%>
    <%= f.hidden_field :url, :value => 'http://delicious.com/' %>
    <%= f.label :delicious %>
    <%= f.text_field :username %>
  </p>
  <p>
    <%= f.submit "Create" %>
  </p>
<% end %>

part of my routes file ( config/routes.rb ):

              map.resources :services, :collection  => { :create
=> :post }

I know should be something stupid, anyway "I'm losing hours" without
success !
Any suggestion will be very apreciated.

thz in advance
luca
++++++++++++++
Request

Parameters:

{"commit"=>"Create",
 "delicious"=>{"url"=>"http://delicious.com/",
 "username"=>"lgsicious"},
 "authenticity_token"=>"xxxxxxxxxxxxxxx"}
++++++++++++++
Response

Headers:

{"cookie"=>[],
 "Cache-Control"=>"no-cache",
 "Allow"=>"GET,
 PUT,
 DELETE"}
+++++++++++++++
Fbd9cb107fe7c941333d6a3488691989?d=identicon&s=25 Ramon Tayag (ramontayag)
on 2008-10-11 22:02
(Received via mailing list)
That happens to me when I edit the routes and forget to restart my
server.

Ramon Tayag
A91bd6cef23eb3516245a092e196c4da?d=identicon&s=25 Maurício Linhares (mauricio)
on 2008-10-12 00:29
(Received via mailing list)
Hi Luca,

First, you don't need this => :collection  => { :create => :post }

just:

map.resources :services

Will do the trick.

Also, your form should be like this:

<% form_for @service do |f| %>
 <%= f.error_messages %>
 <p>
   <%= image_tag("/images/sites_icons/delicious.png") -%>
   <%= f.hidden_field :url, :value => 'http://delicious.com/' %>
   <%= f.label :delicious %>
   <%= f.text_field :username %>
 </p>
 <p>
   <%= f.submit "Create" %>
 </p>
<% end %>

Try this and see if it works.

On Sat, Oct 11, 2008 at 2:17 PM, lgs <luca.soave@gmail.com> wrote:
> delete requests are allowed.
> create
>    <%= image_tag("/images/sites_icons/delicious.png") -%>
>
> Request
> Headers:
>
> {"cookie"=>[],
>  "Cache-Control"=>"no-cache",
>  "Allow"=>"GET,
>  PUT,
>  DELETE"}
> +++++++++++++++
>
> >
>



--
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)
João Pessoa, PB, +55 83 8867-7208
This topic is locked and can not be replied to.