我想在我的应用程序中实现Devise Invitable,但是,它没有按预期工作。现在,电子邮件已正确发送,但是当用户单击accept invitation
链接时,他们没有被发送到可以设置密码的页面,而是被发送到了网站的根目录。更奇怪的是,当我检查accept invite
链接时,超级引用被设置为
http://localhost:3000/users/invitation/accept?invitation_token=aQ9_9eubcMHv-hXuUM3T"
这应该设置为!但这不是送我到那里。似乎一旦用户确实到达页面,Devise Invitable就会自动将用户重定向到主页,而不是呈现允许用户设置密码的表单,我也不知道为什么
这是我的邀请控制器
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
这是我的路线
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
点击接受链接后,我的日志报告如下:
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)
这是我前往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
答案 0 :(得分:0)
使用after_invite_path_for方法覆盖默认路径
class InvitationsController < Devise::InvitationsController
def after_invite_path_for(resource)
#your_path
new_admin_user_invitation_url
end
end