js。erb不执行javascript,而是被处理的rails

时间:2022-05-23 19:18:52

I'm trying to get my pagination working with Ajax, using either will_paginate or kaminari.

我正在尝试使用Ajax进行分页,使用will_paginate或kaminari。

When I hit pagination link my log says

当我点击分页链接时,我的日志说。

Processing by Instructor::FullDashboardController#pupil_leads as JS

and

Rendered instructor/full_dashboard/pupil_leads.js.erb within layouts/main (0.1ms)

But the js has no effect. So to test it I wrote

但js没有效果。为了测试它,我写了

console.log("Hello");
<%logger.debug "This is the js file"%>
alert('Hello Rails');

In the js.erb file, in my log I see This is the js file as expected, but there is nothing in js console in my browser and the alert doesn't show. So I know the file is being processed, as my logger.debug works but there is no js.

js。erb文件,在我的日志中,我看到这是预期的js文件,但是在我的浏览器中,js控制台没有任何内容,警报也没有显示。所以我知道文件正在被处理,作为我的logger.debug工作,但是没有js。

How can I further troubleshoot this?

如何进一步排除故障?

Rails 4.1

Rails 4.1

Ruby 2.1

Ruby 2.1

Full Dash Controller

全部冲控制器

class Instructor::FullDashboardController < ApplicationController
   layout 'main'
...
   def pupil_leads
     @ivar = Model.where("something = ?", some_object.id).order("created_at desc").page(params[:page]).per(10)
     respond_to do |f|
       f.js { render :content_type => 'text/javascript' }
       f.html
     end
  end

1 个解决方案

#1


16  

Add layout: false option to the render block:

向渲染块添加布局:false选项:

def pupil_leads
   # some code here
  respond_to do |f|
    f.js { render layout: false, content_type: 'text/javascript' }
    f.html
  end
end

For some reason Rails don't recognize request as xhr, I also watched that the views extension (.erb.html or .slim) must be specified in full.

由于某些原因,Rails不承认请求作为xhr,我也注意到视图扩展(.erb。html或.slim)必须全部指定。

#1


16  

Add layout: false option to the render block:

向渲染块添加布局:false选项:

def pupil_leads
   # some code here
  respond_to do |f|
    f.js { render layout: false, content_type: 'text/javascript' }
    f.html
  end
end

For some reason Rails don't recognize request as xhr, I also watched that the views extension (.erb.html or .slim) must be specified in full.

由于某些原因,Rails不承认请求作为xhr,我也注意到视图扩展(.erb。html或.slim)必须全部指定。