javascript - 未捕获的语法错误 : Unexpected token < in rails

标签 javascript ruby-on-rails devise

这是我在 StackOverflow 上的第一个问题。我是 Rails 的新手,正在制作一个简单的 Rails 应用程序,其中我正在为用户登录做一个模式弹出窗口。我的代码如下。

应用/ Controller / session :

class Users::SessionsController < Devise::SessionsController
  # respond_to :html, :json
  # before_action :check_user_session, only: [:new]

  # GET /resource/sign_in
  def new
    self.resource = resource_class.new(sign_in_params)
    clean_up_passwords(resource)
    yield resource if block_given?
    respond_to do |format|
      format.js
      format.html
    end
  end

  # POST /resource/sign_in
  def create
    self.resource = warden.authenticate(auth_options)
    if self.resource.present?
      set_flash_message(:notice, :signed_in)
      sign_in(resource_name, resource)
      yield resource if block_given?
      respond_with resource, location: after_sign_in_path_for(resource)
    else
      respond_to do |format|
        format.js
      end
    end
  end

我的new.js.haml 文件:

$("#login-modal").html("#{escape_javascript(render 'new')}");
$("#exampleModal").modal();

单击登录按钮时出现此错误。

最佳答案

使用以下代码将文件 new.js.haml 更改为 new.js.erb:

$("#login-modal").html("<%= escape_javascript(render 'new') %>");
$("#exampleModal").modal();

关于javascript - 未捕获的语法错误 : Unexpected token < in rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47568245/

相关文章:

ruby-on-rails - 我如何设计/omniauth 重定向到我登录的页面?

javascript - Cordova 应用程序中的触发事件

javascript - 使用 JavaScript 动态生成文本框

javascript - lazyload.js 需要在初始加载时显示图像的操作

ruby-on-rails - Rails 中的命名空间模型生成 NameError : uninitialized constant

ruby-on-rails - 在 Rails 中发送项目邀请

javascript - 如何编写检查两个类是否相同的函数

ruby-on-rails - Sidekiq:perform_async 和顺序相关操作

ruby-on-rails - Rails 中的系统调用返回 'No such file or directory'

ruby-on-rails - Rails 设计可确认、可内存