簡體   English   中英

js.erb沒有執行javascript但是處理了rails

[英]js.erb not executing javascript but is processed rails

我正在嘗試使用will_paginate或kaminari使用Ajax進行分頁。

當我點擊分頁鏈接我的日志說

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");
<%logger.debug "This is the js file"%>
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 < 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

添加layout: false渲染塊的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 )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM