js.erb没有执行javascript但是处理了rails
我试图让我的分页使用Ajax,使用will_paginate或kaminari。
当我点击分页链接我的日志说
Processing by Instructor::FullDashboardController#pupil_leads as JS
和
Rendered instructor/full_dashboard/pupil_leads.js.erb within layouts/main (0.1ms)
但是js没有效果。 所以为了测试我写的
console.log("Hello"); alert('Hello Rails');
在js.erb文件中,在我的日志中,我看到This is the js file
预期This is the js file
,但我的浏览器的js控制台中没有任何内容,警报也没有显示。 所以我知道文件正在处理中,因为我的logger.debug工作但没有js。
我该如何进一步排除故障?
Rails 4.1
Ruby 2.1
完全破折号控制器
class Instructor::FullDashboardController 'text/javascript' } f.html end end
为render框添加layout: false
选项:
def pupil_leads # some code here respond_to do |f| f.js { render layout: false, content_type: 'text/javascript' } f.html end end
出于某种原因,Rails不会将请求识别为xhr
,我还.slim
必须完整指定视图扩展名( .erb.html
或.slim
)。