最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - js.erb not executing javascript but is processed rails - Stack Overflow

programmeradmin1浏览0评论

I'm trying to get my pagination working with Ajax, using either will_paginate or 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

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.

How can I further troubleshoot this?

Rails 4.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

I'm trying to get my pagination working with Ajax, using either will_paginate or 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

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.

How can I further troubleshoot this?

Rails 4.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
Share Improve this question edited Nov 25, 2014 at 12:43 LpLrich asked Nov 25, 2014 at 12:20 LpLrichLpLrich 2,5332 gold badges21 silver badges31 bronze badges 3
  • please show full Instructor::FullDashboardController. – Roman Kiselenko Commented Nov 25, 2014 at 12:23
  • It's a bit long for that, do you want the relevant action? – LpLrich Commented Nov 25, 2014 at 12:23
  • post pupil_leads action. – Roman Kiselenko Commented Nov 25, 2014 at 12:24
Add a comment  | 

1 Answer 1

Reset to default 21

Add layout: false option to the render block:

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.

发布评论

评论列表(0)

  1. 暂无评论