我正在使用Rails,Devise gem,jQuery验证插件和Bootstrap。
我可以打电话给$('#congrats')。show();当用户提交,但它正在关闭时,因为用户应该在注册后自动重定向。
另外,如果第一次加载页面,我无法调用,是吗?
如何在适当的时候调用show功能?
我的HTML表格
<form accept-charset="UTF-8" action="/users" class="sign_up" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="W0u6CgL+sA/n/Zecikl67zLqkIPePQz01Vg0u3bi2nc=" /></div>
<div class="field2">
<label for="user_first_name">First name</label>
<input id="user_first_name" name="user[first_name]" size="30" type="text" /></div>
<div class="field2"><label for="user_last_name">Last name</label>
<input id="user_last_name" name="user[last_name]" size="30" type="text" /></div>
<div class="field2"><label for="user_email">Email</label>
<input id="user_email" name="user[email]" size="30" type="email" value="" /></div>
<div class="field2"><label for="user_password">Password</label>
<input id="user_password" name="user[password]" size="30" type="password" /></div>
<div class="field2"><label for="user_password_confirmation">Re-Type Password</label>
<input id="user_password_confirmation" name="user[password_confirmation]" size="30" type="password" />
</div>
<div class="login_submit">
<input class="btn login" name="commit" type="submit" value="Sign up" />
</div>
</form>
答案 0 :(得分:1)
http://guides.rubyonrails.org/action_controller_overview.html#the-flash ..闪存系统只是为了处理这种情况。闪存中设置的值将仅保留一次重定向。如果用户要刷新页面,则将自动取消设置闪存值,用户将不会再次看到该消息。
我不记得erb语法,但我可以编写一些伪代码:
if flash message["signup_success"] == true, then
print this text "var showCongrats = true;"
else print this text "var showCongrats = false;"
在你的js代码中,
$(function() {
if (showCongrats) { // show the modal;
}
})
我们只想让erb向页面打印变量声明。
答案 1 :(得分:0)
你能做的是:
logged_in_successfully
会话变量设置为true
logged_in_successfully
,或将其设置为false
。