"Only get, put, and delete requests are allowed."?

I am getting this error and I can’t for the life of me figure out why this is happening. Even google is not spitting out anything useful.

This is what I have.


map.resources :users, :member => { :edit_email => :get, :edit_password => :get } do |user|

user.resources :pictures



<% form_for(:picture, user_pictures_path(params[:user_id]), :html => { :multipart => true }) do |f| -%>

<%= file_field :picture, :picture %>

<% end -%>


def create

@picture = @user.pictures.build params[:picture]

@picture.file_name = @user.nickname + Time.now.strftime("%Y%m%d%H%M%S")

if (@user.pictures << @picture.save)

redirect_to user_url(@user)


render :action => :new



HELP :slight_smile:

You need to specify the method used by the form tag:

<% form_for(:picture, user_pictures_path(params[:user_id]), :method => :post, :html => { :multipart => true }) do |f| -%>

<%= file_field :picture, :picture %>

<% end -%>


I wish that was it but it is not the case. I am getting the same error and I do not think it matters if I set method or not because even if I do not set the method it is by default set as a post.

Any other suggestions please? :frowning:

Just some standard debugging advice: start taking stuff out until it
works. What happens if the form doesn't contain upload fields? What if
create is empty?


I did that… I have the following and I am still having the same problem:


<% form_for(:picture, user_pictures_path(params[:user_id]), :html => { :method => :post }) do |f| -%>

<p><%= submit_tag 'Upload' %></p>

<% end -%>


def create

render :text => “hello”



map.resources :users, :member => { :edit_email => :get, :edit_password => :get } do |user|

user.resources :pictures


I have a funny feeling this has something to do with the fact this is a nested resource. I have found other people with the same problem and they were using nested resources as well but I could never find their solution :-).

Any feedback?

I think I figured it out:

rake routes | grep picture

user_pictures GET /users/:user_id/pictures {:action=>“index”, :controller=>“pictures”}

formatted_user_pictures GET /users/:user_id/pictures.:format {:action=>“index”, :controller=>“pictures”}

POST /users/:user_id/pictures {:action=>“create”, :controller=>“pictures”}

POST /users/:user_id/pictures.:format {:action=>“create”, :controller=>“pictures”}

new_user_picture GET /users/:user_id/pictures/new {:action=>“new”, :controller=>“pictures”}

formatted_new_user_picture GET /users/:user_id/pictures/new.:format {:action=>“new”, :controller=>“pictures”}

edit_user_picture GET /users/:user_id/pictures/:id/edit {:action=>“edit”, :controller=>“pictures”}

formatted_edit_user_picture GET /users/:user_id/pictures/:id/edit.:format {:action=>“edit”, :controller=>“pictures”}

user_picture GET /users/:user_id/pictures/:id {:action=>“show”, :controller=>“pictures”}

formatted_user_picture GET /users/:user_id/pictures/:id.:format {:action=>“show”, :controller=>“pictures”}

PUT /users/:user_id/pictures/:id {:action=>“update”, :controller=>“pictures”}

PUT /users/:user_id/pictures/:id.:format {:action=>“update”, :controller=>“pictures”}

DELETE /users/:user_id/pictures/:id {:action=>“destroy”, :controller=>“pictures”}

DELETE /users/:user_id/pictures/:id.:format {:action=>“destroy”, :controller=>“pictures”}

POST AND DELETE do not have methods for creating the URL… you have to just pass the :url with an :action and :controller. Does anyone know why this is the case?

in your routes.rb add :collection => {:new=>:any}

map.resources :users, :member => { :edit_email => :get, :edit_password
:get } do |user|
    user.resources :pictures,:collection => {:new=>:any}

It worked for me