"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.

route:

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

pictures/new.html.erb

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

pictures_controller.rb

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)
else
render :action => :new
end
end

HELP :slight_smile:


John K.
[email protected]

Blog: http://www.kopanas.com
Conference: http://www.cusec.net
Twits: http://www.twitter.com/kopanas

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?

///ark

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

new.html.erb

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

<%= submit_tag 'Upload' %>

<% end -%>

pictures_controller.rb

def create
render :text => “hello”
end

routes.rb

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

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?

On Dec 12, 2007 12:30 PM, Mark W. [email protected] wrote:

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?

///ark


John K.
[email protected]

Blog: http://www.kopanas.com
Conference: http://www.cusec.net
Twits: http://www.twitter.com/kopanas

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?

On Dec 12, 2007 12:37 PM, John K. [email protected] wrote:

user.resources :pictures


John K.
[email protected]

Blog: http://www.kopanas.com
Conference: http://www.cusec.net
Twits: http://www.twitter.com/kopanas


John K.
[email protected]

Blog: http://www.kopanas.com
Conference: http://www.cusec.net
Twits: http://www.twitter.com/kopanas

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:

On Dec 12, 2007 8:42 AM, Jason R. [email protected] wrote:

user.resources :pictures


John K.
[email protected]

Blog: http://www.kopanas.com
Conference: http://www.cusec.net
Twits: http://www.twitter.com/kopanas

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}
end

It worked for me


[email protected]

On Dec 11, 2007 10:04 PM, John K. [email protected] wrote:

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

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 -%>

Jason