Rails 3.1.3 unable to access the file inside assets/javascripts folder

好久不见. 提交于 2019-12-12 01:03:43

问题


I have put fancybox (jquery plugin ) inside the assets/javascripts/includes/jquery.fancybox-1.3.4

Before this location i also tried to put it under /vendor/assets/stylesheets/jquery directory.

I am getting this weird error & why isn't rails able to get the particular file when its right there.

------------- Development Log ----------------

Started GET "/vendor/assets/stylesheets/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack.js" for 127.0.0.1 at 2011-11-25 13:30:42 -0800

ActionController::RoutingError (No route matches [GET] "/vendor/assets/stylesheets/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack.js"):

Rendered /Users/jayparteek/.rvm/gems/ruby-1.9.2-head@default/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.5ms)

-------------- Log 2 -------------------------

ActionController::RoutingError (No route matches [GET] "/vendor/assets/javascripts/fancybox-1.3.4/jquery.fancybox-1.3.4.pack.js"):


回答1:


Simply use the fancy box gem https://github.com/hecticjeff/fancybox-rails




回答2:


Rails doesn't load your */assets/javascripts tree automatically, just the files in that directory. And by default, it will only precompile application.js and anything with a non .js extension.

I would recommend you rename the fancybox file to just fancybox-1.3.4.js. With Rails 3.1, assets are concatenated and minified before output, so there's not much need to even use the minified version, though it won't hurt anything if you do.

You should put jQuery plugins directly in vendor/assets/javascripts/, then include them into the appropriate file (probably application.js) in app/assets/javascripts, like so (assuming application.js):

//= require jquery
//= require fancybox-1.3.4
//= [any other requires here]
//= require_self

Then you use javascript_include_tag 'application' in your layout. Voila!



来源:https://stackoverflow.com/questions/8274418/rails-3-1-3-unable-to-access-the-file-inside-assets-javascripts-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!