简体   繁体   English

将邀请发送用户设计为根路由,而不是邀请页面

[英]Devise invitable sending user to root route instead of invitation page

I want to implement Devise Invitable into my app, however, It isn't working as expected. 我想在我的应用程序中实现Devise Invitable,但是,它没有按预期工作。 Right now The email sends correctly, but when the user clicks on the accept invitation link, they don't get sent to a page where they can set their password, they get sent to the root route of the website. 现在,电子邮件已正确发送,但是当用户单击accept invitation链接时,他们没有被发送到可以设置密码的页面,而是被发送到了网站的根目录。 What's even weirder is that when I inspect the accept invite link, the hyper reference is set to http://localhost:3000/users/invitation/accept?invitation_token=aQ9_9eubcMHv-hXuUM3T" 更奇怪的是,当我检查accept invite链接时,超级引用设置为http://localhost:3000/users/invitation/accept?invitation_token=aQ9_9eubcMHv-hXuUM3T"

That is what is supposed to be set to! 那是应该设置的! But it's not sending me there. 但这不是送我到那里。 It seems as though once the users does arrive to the page, Devise Invitable automatically redirects the user to the home page instead of rendering the form which allows the user to set their password, and I have no idea why 似乎一旦用户到达页面,Devise Invitable就会自动将用户重定向到主页,而不是呈现允许用户设置密码的表单,我也不知道为什么

here is my invitations controller 这是我的邀请控制器

class Users::InvitationsController < Devise::InvitationsController 
  before_action :configure_permitted_parameters

  protected 
  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:accept_invitation, keys: [:first_name, :last_name])
  end
end

and here are my routes 这是我的路线

Rails.application.routes.draw do

  devise_for :users, controllers: { invitations: 'users/invitations' }
  root 'pages#home'

  get '/dashboard', to: 'dashboard#index'
  namespace :dashboard do
    resources :projects do 
      post :toggle_status
    end
    resources :users, except: [:edit, :update]
  end
end

Here is what my logs report as soon as I click the accept link: 单击接受链接后,以下是我的日志报告:

Started GET "/users/invitation/accept?invitation_token=nXxxSxP8vC3yUogm9yzx" for 127.0.0.1 at 2018-08-26 21:33:37 -0600
Processing by Users::InvitationsController#edit as HTML
  Parameters: {"invitation_token"=>"nXxxSxP8vC3yUogm9yzx"}
  User Load (0.8ms)  SELECT  "users".* FROM "users" WHERE "users"."invitation_token" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["invitation_token", "a807392954389f3dd2054bfe03567b5419d6da7212f1c490ee2b46a9641037a6"], ["LIMIT", 1]]
  ↳ /Users/angelgarcia/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
  User Load (0.8ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 20], ["LIMIT", 1]]
  ↳ /Users/angelgarcia/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
Redirected to http://localhost:3000/
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 9ms (ActiveRecord: 1.6ms)


Started GET "/" for 127.0.0.1 at 2018-08-26 21:33:37 -0600
Processing by PagesController#home as HTML
  Rendering pages/home.html.erb within layouts/application
  Rendered pages/home.html.erb within layouts/application (0.8ms)
Completed 200 OK in 83ms (Views: 76.7ms | ActiveRecord: 0.0ms)

Here are my routes for Devise 这是我的设计路线

cancel_user_registration GET    /users/cancel(.:format)                                                                  devise_invitable/registrations#cancel
          new_user_registration GET    /users/sign_up(.:format)                                                                 devise_invitable/registrations#new
         edit_user_registration GET    /users/edit(.:format)                                                                    devise_invitable/registrations#edit
              user_registration PATCH  /users(.:format)                                                                         devise_invitable/registrations#update
                                PUT    /users(.:format)                                                                         devise_invitable/registrations#update
                                DELETE /users(.:format)                                                                         devise_invitable/registrations#destroy
                                POST   /users(.:format)                                                                         devise_invitable/registrations#create
         accept_user_invitation GET    /users/invitation/accept(.:format)                                                       users/invitations#edit
         remove_user_invitation GET    /users/invitation/remove(.:format)                                                       users/invitations#destroy
            new_user_invitation GET    /users/invitation/new(.:format)                                                          users/invitations#new
                user_invitation PATCH  /users/invitation(.:format)                                                              users/invitations#update
                                PUT    /users/invitation(.:format)                                                              users/invitations#update
                                POST   /users/invitation(.:format)                                                              users/invitations#create

Override the default path by using after_invite_path_for method 使用after_invite_path_for方法覆盖默认路径

class InvitationsController < Devise::InvitationsController

  def after_invite_path_for(resource)
   #your_path
   new_admin_user_invitation_url
  end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM