This project is archived and is in readonly mode.

#5553 ✓invalid
RailsFanatic

Post directive in nested singleton resource route doesn't work

Reported by RailsFanatic | September 5th, 2010 @ 08:22 AM

On POST in the browser:

Routing Error

No route matches "/account/passphrase/authenticate"

But it does too, dammit!!!

In fact, I know this because GET /account/passphrase/confirm_destroy works fine!!!
It's only the post directive under a nested singleton resource that doesn't work.

In routes.rb:

resource :account, :controller => :account, :only => [:show, :edit, :update] do
  # this is NOT the actual account password, it's something else!!!!
  resource :passphrase, :controller => 'account/passphrase' do
    post :authenticate
    get :confirm_destroy
  end
end

rake routes are correct:

authenticate_account_passphrase POST /account/passphrase/authenticate(.:format) {:action=>"authenticate", :controller=>"account/passphrase"} confirm_destroy_account_passphrase GET /account/passphrase/confirm_destroy(.:format) {:action=>"confirm_destroy", :controller=>"account/passphrase"}

            account_passphrase POST   /account/passphrase(.:format)                 {:action=>"create", :controller=>"account/passphrase"}
        new_account_passphrase GET    /account/passphrase/new(.:format)             {:action=>"new", :controller=>"account/passphrase"}
       edit_account_passphrase GET    /account/passphrase/edit(.:format)            {:action=>"edit", :controller=>"account/passphrase"}
            account_passphrase GET    /account/passphrase(.:format)                 {:action=>"show", :controller=>"account/passphrase"}
            account_passphrase PUT    /account/passphrase(.:format)                 {:action=>"update", :controller=>"account/passphrase"}
            account_passphrase DELETE /account/passphrase(.:format)                 {:action=>"destroy", :controller=>"account/passphrase"}

In the controller:

class Account::PassphraseController < ApplicationController
... # GET /account/passphrase # form for authenticating def show

@keypair = current_account.keypair

end

# POST /account/passphrase def create

...

end

# POST /account/passphrase/authenticate def authenticate

@keypair = current_account.keypair
...

end end

In the view:

Please enter your secret passphrase.

<%= form_for @keypair, :url => authenticate_account_passphrase_path do |f| %> Route works fine in the view: authenticate\_account\_passphrase\_path And in rake routes. What's with the??? Routing Error No route matches "/account/passphrase/authenticate" When GET /account/passphrase/confirm_destroy works fine???

Comments and changes to this ticket

  • Andrew White

    Andrew White September 5th, 2010 @ 09:36 PM

    • State changed from “new” to “invalid”
    • Importance changed from “” to “Low”

    When using form_for with an existing record then it will default to PUT rather than POST as that's the pattern for an update when using RESTful routes. Either specify the method in your form_for call or change your route to put :authenticate and it will work.

  • Ryan Bigg

    Ryan Bigg October 11th, 2010 @ 12:10 PM

    • Tag cleared.

    Automatic cleanup of spam.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages