Ben Wheeler
Ben Wheeler

Reputation: 7354

Why is devise not obeying route?

Note: as usual with SO, I solved my problem in the course of clarifying it to ask it here! Solution is at end.

Rails isn't sending devise invitation URL requests to the right place.

When I go to:

http://localhost:3000/users/invitation/accept?invitation_token=SOME_TOKEN

the browser just redirects to root.

routes.rb is sending requests to my custom devise controllers, like:

devise_for :users, :controllers => { passwords: 'passwords', sessions: "sessions", invitations: 'users/invitations'}

devise.rb has scoped views enabled:

config.scoped_views = true

rake routes gives me:

accept_user_invitation GET /users/invitation/accept(.:format)  users/invitations#edit

and users/invitations_controller.rb is like:

class Users::InvitationsController < Devise::InvitationsController
  def edit
    # Try to catch rails if it resolves to this method like i want it to!
    # It fails to get here, though.
    byebug # elsewhere in my code, byebug successfully acts as breakpoint
    super
  end
end

So why is it redirecting to root?

I've gotten it to resolve to my custom edit method, but ONLY by removing the invitations controller from devise_for AND renaming it (as "accept") and explicitly making it a route:

devise_scope :user do
  scope'/users' do
    get '/invitation/accept' => 'users/invitations#accept', as: 'custom_accept_user_invitation'
  end
end

In case this is a cacheing issue, I've erased my Chrome DNS cache, restarted rails server and redis-server, and run rake tmp:cache:clear.

UPDATE: Solution

The issue was that I was already signed in to my site using some other account, so when I would attempt to accept a devise_invitable invitation, devise would redirect me to root!

I logged out and tried the URL again, and it worked fine!

Upvotes: 0

Views: 59

Answers (1)

Ben Wheeler
Ben Wheeler

Reputation: 7354

The issue was that I was already signed in to my site using some other account, so when I would attempt to accept a devise_invitable invitation, devise would redirect me to root!

I logged out and tried the URL again, and it worked fine!

Upvotes: 1

Related Questions