在 Rails 4.x webapp 上使用 Devise 确认注册后将用户重定向到模式弹出窗口
Redirect user to modal popup after registration confirmation using Devise on Rails 4.x webapp
在 Rails 4.x 应用程序上,我正在使用 Devise 注册用户。我想要做的是在确认后将用户重定向到通常的 user_path(resource) 但是有一个模式似乎提示一些事情。我不知道如何在不使用 cookie 和 javascript 的情况下解决这个问题。有人以前解决过这个问题或者知道在 Devise 中使用标准 after_confirmation_path_for 方式来解决这个问题吗?如果没有,您认为最好的解决方法是什么?
非常感谢。
好的,如果其他人遇到这个问题。我只找到一种解决方法,就是这样:
confirmations_controller.rb
class ConfirmationsController < Devise::ConfirmationsController
private
def after_confirmation_path_for(resource_name, resource)
sign_in(resource)
user_path(resource[:id], cp: true)
end
end
然后在我想弹出模式的视图中,我使用了这个相当流行的 javascript 答案 (How can I get query string values in JavaScript?) show.html.erb:
<%= javascript_tag do -%>
window.onload = function() {
var doCP = getParameterByName('cp');
if (doCP) {
$("#modal").html("<%= escape_javascript(render 'confirm_prompt_form') %>");
$("#modal").modal("show");
}
}
function getParameterByName(name) {
name = name.replace(/[\[]/, "\[").replace(/[\]]/, "\]");
var regex = new RegExp("[\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
在 Rails 4.x 应用程序上,我正在使用 Devise 注册用户。我想要做的是在确认后将用户重定向到通常的 user_path(resource) 但是有一个模式似乎提示一些事情。我不知道如何在不使用 cookie 和 javascript 的情况下解决这个问题。有人以前解决过这个问题或者知道在 Devise 中使用标准 after_confirmation_path_for 方式来解决这个问题吗?如果没有,您认为最好的解决方法是什么?
非常感谢。
好的,如果其他人遇到这个问题。我只找到一种解决方法,就是这样:
confirmations_controller.rb
class ConfirmationsController < Devise::ConfirmationsController
private
def after_confirmation_path_for(resource_name, resource)
sign_in(resource)
user_path(resource[:id], cp: true)
end
end
然后在我想弹出模式的视图中,我使用了这个相当流行的 javascript 答案 (How can I get query string values in JavaScript?) show.html.erb:
<%= javascript_tag do -%>
window.onload = function() {
var doCP = getParameterByName('cp');
if (doCP) {
$("#modal").html("<%= escape_javascript(render 'confirm_prompt_form') %>");
$("#modal").modal("show");
}
}
function getParameterByName(name) {
name = name.replace(/[\[]/, "\[").replace(/[\]]/, "\]");
var regex = new RegExp("[\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}