LpL*_*ich 4 javascript ruby jquery ruby-on-rails
我正在尝试使用will_paginate或kaminari使用Ajax进行分页.
当我点击分页链接我的日志说
Processing by Instructor::FullDashboardController#pupil_leads as JS
Run Code Online (Sandbox Code Playgroud)
和
Rendered instructor/full_dashboard/pupil_leads.js.erb within layouts/main (0.1ms)
Run Code Online (Sandbox Code Playgroud)
但是js没有效果.所以为了测试我写的
console.log("Hello");
<%logger.debug "This is the js file"%>
alert('Hello Rails');
Run Code Online (Sandbox Code Playgroud)
在js.erb文件中,在我的日志中,我看到This is the js file了预期,但在浏览器的js控制台中没有任何内容,并且警报未显示.所以我知道文件正在处理中,因为我的logger.debug工作但是没有js.
我该如何进一步排除故障?
Rails 4.1
Ruby 2.1
完整的短跑控制器
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
Run Code Online (Sandbox Code Playgroud)
Зел*_*ный 19
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
Run Code Online (Sandbox Code Playgroud)
出于某种原因,Rails不会将请求识别为xhr,我还注意到必须完整指定视图扩展名(.erb.html或.slim).