weixin_33686714 2016-02-28 18:52 采纳率: 0%
浏览 34

format.js未执行(ajax)

I'm trying to add email confirmation when signing up users. Users have to fill out a form with their invitation code and email address, and then they get an email with an activation link.

So all I want to do is have it so when the user fills out the form, it submits the form and reloads the form so that it hides and displays the message "we sent you an email, please check and click the link" instead of reloading the entire page.

signup.html.erb

here I've added remote: true

<%= form_tag(form_action, method: :get, remote: true, id: 'create-form') do %>

users_controller.rb

the redirect works but format.js is an unknown format

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
end

new.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>');

not sure what I am missing, any ideas?

  • 写回答

1条回答 默认 最新

  • weixin_33691700 2016-02-28 21:21
    关注

    I really do not think that the action the form is calling when submitting is your new action, it may be some create action in your controller.

    So when you hit the "submit" button of your form it is sent through Ajax due to you have remote: true option, and the action it is calling does not have a format.js nor js.erb view, That's why you get unknown format.

    Make sure which controller action is being called when you submit your form, then add the format.js and the proper js.erb view.

    Please take a look to this blog post, it may be helpful.

    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?