新手问题 生产环境下,rake assets:precompile 后出现 TypeError: unknown filter type 错误

zorajiang · 2015年06月18日 · 最后由 afgnsu 回复于 2015年11月27日 · 2699 次阅读

写在前面,贴的 log 比较多,刚学 ruby 还不懂怎么描述的专业些些,请轻喷~

我在工程里用到了 rails_kindeditor 的 gem,并按 github 上 rails_kindeditor 上的步骤进行了配置,在开发环境中运行良好,但在生产环境下(ubuntu+ passenger 5.0+ nginx 1.8+rails 4.2)错误如下:

$ bundle exec rake assets:precompile RAILS_ENV=production --trace
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Execute assets:precompile
rake aborted!
TypeError: unknown filter type: #<Pathname:kindeditor/lang/zh_CN.js>
/usr/local/lib/ruby/gems/2.2.0/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:296:in `compile_match_filter'
/usr/local/lib/ruby/gems/2.2.0/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:125:in `block in find'
/usr/local/lib/ruby/gems/2.2.0/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:125:in `map'
/usr/local/lib/ruby/gems/2.2.0/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:125:in `find'
/usr/local/lib/ruby/gems/2.2.0/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:162:in `compile'
/usr/local/lib/ruby/gems/2.2.0/gems/sprockets-rails-2.3.1/lib/sprockets/rails/task.rb:70:in `block (3 levels) in define'
/usr/local/lib/ruby/gems/2.2.0/gems/sprockets-3.2.0/lib/rake/sprocketstask.rb:147:in `with_logger'
/usr/local/lib/ruby/gems/2.2.0/gems/sprockets-rails-2.3.1/lib/sprockets/rails/task.rb:69:in `block (2 levels) in define'
/usr/local/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/usr/local/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/usr/local/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/usr/local/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/usr/local/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/usr/local/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/usr/local/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/usr/local/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/usr/local/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/usr/local/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/usr/local/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/usr/local/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/usr/local/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/usr/local/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/usr/local/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/usr/local/bin/rake:33:in `<main>'
Tasks: TOP => assets:precompile

界面上的表现则是加载不了 js 和 css 文件,nginx 的 errorlog 如下:

App 14026 stdout: Started GET "/stylesheets/application.css" for 119.49.5.203 at 2015-06-18 12:40:51 +0800
App 14026 stdout: 
App 14026 stdout: ActionController::RoutingError (No route matches [GET] "/stylesheets/application.css"):
App 14026 stdout:   actionpack (4.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
App 14026 stdout:   actionpack (4.2.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
App 14026 stdout:   railties (4.2.1) lib/rails/rack/logger.rb:38:in `call_app'
App 14026 stdout:   railties (4.2.1) lib/rails/rack/logger.rb:20:in `block in call'
App 14026 stdout:   activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
App 14026 stdout:   activesupport (4.2.1) lib/active_support/tagged_logging.rb:26:in `tagged'
App 14026 stdout:   activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `tagged'
App 14026 stdout:   railties (4.2.1) lib/rails/rack/logger.rb:20:in `call'
App 14026 stdout:   actionpack (4.2.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
App 14026 stdout:   rack (1.6.1) lib/rack/methodoverride.rb:22:in `call'
App 14026 stdout:   rack (1.6.1) lib/rack/runtime.rb:18:in `call'
App 14026 stdout:   activesupport (4.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
App 14026 stdout:   actionpack (4.2.1) lib/action_dispatch/middleware/static.rb:113:in `call'
App 14026 stdout:   rack (1.6.1) lib/rack/sendfile.rb:113:in `call'
App 14026 stdout:   railties (4.2.1) lib/rails/engine.rb:518:in `call'
App 14026 stdout:   railties (4.2.1) lib/rails/application.rb:164:in `call'
App 14026 stdout:   passenger (5.0.10) lib/phusion_passenger/rack/thread_handler_extension.rb:94:in `process_request'
App 14026 stdout:   passenger (5.0.10) lib/phusion_passenger/request_handler/thread_handler.rb:149:in `accept_and_process_next_request'
App 14026 stdout:   passenger (5.0.10) lib/phusion_passenger/request_handler/thread_handler.rb:110:in `main_loop'
App 14026 stdout:   passenger (5.0.10) lib/phusion_passenger/request_handler.rb:414:in `block (3 levels) in start_threads'
App 14026 stdout:   passenger (5.0.10) lib/phusion_passenger/utils.rb:111:in `block in create_thread_and_abort_on_exception'

我已经运行过 rake kindeditor:assets,public/assets 下也已经存在 kindeditor/lang/zh_CN.js

$ls public/assets/kindeditor/
kindeditor.js  lang  plugins  themes
$ls public/assets/kindeditor/lang
ar.js  en.js  ko.js  zh_CN.js  zh_TW.js

上网找了下 TypeError: unknown filter type 的解决办法,找到了这个帖子 TypeError: unknown filter type: #Pathname:spree/backend/all.js , 但还是木有解决我的问题啊😭

后来我将 rails_kindeditor 换成了 ckeditor,重新部署了一次,可以正常 precompile,页面也表现正常了。但是,总觉得不应该是 rails_kindeditor 导致的问题,可能是我的 config 配置有问题?🙏 大家帮忙分析下~

-    sprockets (3.2.0)
+    sprockets (2.12.3)
+      hike (~> 1.2)
+      multi_json (~> 1.0)
       rack (~> 1.0)
-    sprockets-rails (2.3.1)
+      tilt (~> 1.1, != 1.3.0)
+    sprockets-rails (2.2.4)

我也遇到了,是因为 sprockets 升级了的缘故,解决办法就是降到 2.12.3

@kikyous 按你的方法修改了,可以正常运行了,非常感谢~

#2 楼 @zorajiang 其实应该使用这个分支:https://github.com/javyliu/rails_kindeditor,不过看起来这个编辑器好久没人更新了。。

很好的一個編輯器,怎麼都沒人在更新了呢? XD

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册