我正在使用Devise Invitable,我在SO(here is one)上發現了幾個答案,這些答案表明我應該在我的Users::InvitationsController < DeviseController
中指定動作after_invite_path_for(resource)
。如何在發送邀請後更改重定向路徑?
我試過了,它仍然不起作用。
這是我的控制器:
class Users::InvitationsController < Devise::InvitationsController
def after_invite_path_for(resource)
root_path
end
def create
@member ||= Member.find_or_create_by(email: params[:user][:email], first_name: get_first_name(params[:user][:full_name]), last_name: get_last_name(params[:user][:full_name]), bio: params[:user][:bio], gender: params[:user][:gender])
@membership ||= Membership.find_or_create_by(member: @member, family_tree: current_user.family_tree, inviter: current_user, relation: params[:user][:invitation_relation])
if @user_exists ||= invited_user_exists(params[:email])
else
super
end
end
end
當我嘗試只需添加一個redirect_to root_path
在else
塊super
之後....這將引發約重定向錯誤已經被調用。
我認爲這是事實,因爲如果您檢查create action here的來源,您將看到重定向。
這是服務器日誌:
Started POST "https://stackoverflow.com/users/invitation" for 127.0.0.1 at 2015-12-02 03:58:57 -0500
Processing by Users::InvitationsController#create as HTML
Rendered users/mailer/invitation_instructions.html.erb within layouts/mail (1.2ms)
# truncated for brevity
Rendered users/invitations/create.html.erb within layouts/devise (0.6ms)
Rendered shared/_navbar.html.erb (1424.4ms)
Completed 200 OK in 9221ms (Views: 4732.1ms | ActiveRecord: 102.0ms)
注意,它從來沒有在任何地方重定向。
可能重複的[Rails設計發送邀請後的Invitable重定向](http://stackoverflow.com/questions/12720612/rails-devise-invitable-redirect-after-send-invititaion) –
@PardeepDhingra這是問題和回答我在我的問題中提到。我的問題的整個前提是基於另一個不起作用的事實。 – marcamillion