Rails 3.1 asset pipeline with suburis

元气小坏坏 提交于 2019-12-13 02:12:07

问题


I'm trying to convert a Rails 3.1 app to use the asset pipeline. Currently using Rails 3.2.0.rc2. I'm setting ENV['RAILS_RELATIVE_URL_ROOT'] to the suburi in application.rb. The helpers work fine, generating the correct path (including the suburi) to the file, however Rails routes aren't serving the files off of that path.

For instance, <%= stylesheet_link_tag 'screen', :media => 'screen' %> correctly generates the code <link href="/my-suburi/assets/screen.css" media="screen" rel="stylesheet" type="text/css" />, however Rails won't serve anything off of this address.

If I manually point my browser at http://localhost:3000/my-suburi/assets/screen.css I get a ActionController::RoutingError. However, if I point it at http://localhost:3000/assets/screen.css I get the file. Everything else works fine with the sub-uris.

Anybody have any idea what I might be missing? Thanks.


回答1:


Figured it out myself. In application.rb, I added...

config.assets.prefix = "/my-suburi"

and then restarted the server. That changed the path in the header to be "/my-suburi/screen.css" (notice the lack of 'assets'), but I confirmed that it is correctly pulling from the /app/assets/stylesheets folder, now.



来源:https://stackoverflow.com/questions/8828472/rails-3-1-asset-pipeline-with-suburis

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