使用PhantomJS预编译把手模板

时间:2015-11-09 08:11:59

标签: ruby-on-rails-4 backbone.js phantomjs

我有一个rails应用程序作为后端,一个BackboneJS应用程序作为前端。 BackboneJS应用程序以rails服务器启动。现在,我有一个搜索引擎索引我的应用程序页面的问题,我试图用phantomjs [我用户this gem]解决。我在应用程序控制器中编写了一个before_filter,如下所示:

  def phantom_response
    if params["_escaped_fragment_"].present?
      url = "#{request.base_url}/#!#{params["_escaped_fragment_"]}"
      output = Phantomjs.run('/lib/assets/get_page.js', url)
      render :text => output
   end
end

我的get_page.js看起来像这样:

    var page = require('webpage').create();
    page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';
    page.settings.localToRemoteUrlAccessEnabled = true;
    page.open(phantom.args[0], function (d) {
       var body = page.evaluate(function(s) {
       return document.querySelector(s).innerText;
       }, '#provider_details_tpl');
    console.log(body);
    phantom.exit();
    });

带有“provider_details_tpl”的元素包含一个把手模板。

但是phantomjs只返回我的模板而没有预编译。你能救我吗?

0 个答案:

没有答案
相关问题