Rails DataTables无法设置sSwfPath

时间:2013-02-26 11:04:01

标签: ruby-on-rails-3.2 flash datatables

我正在开发一个本地应用程序。 我尝试将TableTools添加到我的dataTables。 TableTools按钮很好地显示在页面上,但它们没有任何效果,我总是有关于swfPath的路由错误。

让TableTools在本地工作的正确方法是什么? 谢谢你的帮助

的application.js

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require dataTables/jquery.dataTables
//= require dataTables/jquery.dataTables.bootstrap
//= require dataTables/extras/TableTools
//= require dataTables/extras/ZeroClipboard
//= require_tree .

users.js.coffee

jQuery ->

  #  Init the table
  $('#users-grid').dataTable
    bjQueryUI: true
    sDom: 'T<"clear"><"fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix"lfr>t<"fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix"ip>'
    oTableTools:
      sSwfPath: "swf/copy_csv_xls_pdf.swf"
    sPaginationType: "bootstrap"
    bProcessing: true
    bServerSide: true
    sAjaxSource: $('#users-grid').data('source')

服务器日志

Started GET "/backstage/swf/copy_csv_xls_pdf.swf" for 127.0.0.1 at 2013-02-26 11:48:11 +0100

ActionController::RoutingError (No route matches [GET]   "/backstage/swf/copy_csv_xls_pdf.swf"):
  actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
  quiet_assets (1.0.1) lib/quiet_assets.rb:20:in `call_with_quiet_assets'
  actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.5) lib/rack/runtime.rb:17:in `call'
 activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
 rack (1.4.5) lib/rack/lock.rb:15:in `call'
 actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:in `call'
 railties (3.2.1) lib/rails/engine.rb:479:in `call'
 railties (3.2.1) lib/rails/application.rb:220:in `call'
 rack (1.4.5) lib/rack/content_length.rb:14:in `call'
 railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call'
 rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
 C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
 C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
 C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

  Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.0ms)

我尝试了不同的事情没有结果(复制我的app / assets目录中的'media'目录,或者我的assets / backstage /'目录中的swf目录等等)没有运气

非常感谢任何帮助

1 个答案:

答案 0 :(得分:8)

已解决!

好的问题是Flash(像往常一样)确实对本地设置了一些限制。如果您将应用程序放在Web服务器上,一切正常... 但是在这种情况下我只需要在我的本地PC上开发并使用localhost作为webserver Flash就可以了。 经过谷歌搜索并尝试了很多我找到了一个有效的解决方案,我把它放在一起以防万一对别人有帮助:

我在Windows8上使用Rails 3.2.11和Ruby 1.9.3(通过RailsInstaller安装)

1-以避免本地Flash限制(Flash不授权加载本地文件)转到http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html#119065和“始终授权”

2 - 从DataTable中找到'swf'目录(我的目录位于:C:\ RailsInstaller \ Ruby1.9.3 \ lib \ ruby​​ \ gems \ 1.9.1 \ gems \ jquery-datatables-rails-1.11.2 \ vendor \ assets \ media \ dataTables \ extras \ swf)将其复制/粘贴到你的app / public /...

3将sSwfPath设置为

sSwfPath: "http://localhost:3000/swf/copy_csv_xls_pdf.swf"

已经完成,一切都应该有效。传入生产时不要忘记更改sSwfPath!

希望这会有所帮助

干杯