我试图在注册用户时添加电子邮件确认。用户必须填写一份包含他们的邀请代码和电子邮件地址的表单,然后他们得到一个带有激活链接的电子邮件。
所以我想做的就是,当用户填写表单时,它提交表单并重新加载表单,以便隐藏并显示“我们发送给您的电子邮件,请检查并单击链接”,而不是重新加载整个页面。
signup.html.erb
这里我添加了remote:真
<%= form_tag(form_action, method: :get, remote: true, id: 'create-form') do %>
users_controller.rb
重定向工作,但format.js是未知格式
def new
... code checking params
if @user.user_email_confirmed
render :new
else
respond_to do |format|
format.html { redirect_to signup_path(@user.name, email: @user.email) }
format.js
end
endnew.js.erb
$('#create-form').hide().after('');
$('.login-form').append('<p class="link-sent">We have sent an activation link to the email address you entered - please be sure to check your spam or trash folders. Please click that link to complete account activation.</p>');不知道我错过了什么,有什么想法吗?
发布于 2016-02-28 21:21:13
我真的不认为表单在提交时调用的操作是您的new操作,它可能是控制器中的一些create操作。
因此,当您按下表单的“提交”按钮时,它会通过Ajax发送,因为您有remote: true选项,并且它调用的操作没有format.js或js.erb视图,这就是为什么您得到未知格式的原因。
在提交表单时,确保调用了哪个控制器操作,然后添加format.js和适当的js.erb视图。
请看一下这个博客帖子,它可能会有帮助。
https://stackoverflow.com/questions/35686803
复制相似问题