Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Post directive in nested singleton resource route doesn't work

#5553

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

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

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Andrew White
    Andrew White
    • 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.

    September 5th, 2010 @ 09:36 PM

  2. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 11th, 2010 @ 12:10 PM