简体   繁体   English

Rails 3:范围:路由:JS / CSS帮助器

[英]Rails 3: Scopes: Routing: JS/CSS helpers

I want to run my Rails application in a different scope so that I can deploy it in a war file (mydepartment.war) which will share a Tomcat instance with another Java app WAR. 我想在其他范围内运行Rails应用程序,以便可以将其部署在war文件(mydepartment.war)中,该文件将与另一个Java应用程序WAR共享一个Tomcat实例。 The solution I chose was to modify the rackup file (/config.ru). 我选择解决方案是修改机架文件(/config.ru)。

map '/mydepartment' do
   run Myapp::Application
end 

When I do this, my base URL becomes http://localhost:3000/mydepartment instead of just http://localhost:3000 . 当我这样做时,我的基本URL变为http:// localhost:3000 / mydepartment,而不仅仅是http:// localhost:3000 The application runs fine, but it doesn't download CSS/JS specified by stylesheet and script helpers. 该应用程序运行正常,但不会下载样式表和脚本助手指定的CSS / JS。

However, when I try to include stylesheets and Javascript using helpers, such as 但是,当我尝试使用帮助器(例如)添加样式表和Javascript时

<%= stylesheet_link_tag :all %>
<%= javascript_include_tags :defaults %>

The URLs they generate include localhost:3000/javascripts/jquery.js instead of localhost:3000/mydepartment/javascripts/jquery.js . 他们生成的URL包括localhost:3000 / javascripts / jquery.js而不是localhost:3000 / mydepartment / javascripts / jquery.js I actually tried typing the latter in the browser, and the sheet downloads fine. 实际上,我尝试在浏览器中键入后者,然后工作表下载正常。

How can I coax the Rails Javascript/CSS helpers to download files in the new scope without hardcoding it? 如何哄骗Rails Javascript / CSS帮助程序下载新范围的文件而无需对其进行硬编码?

if you're not on rails 3.1: 如果您不在轨道3.1上:

Add this to your config/environments/production.rb (if on production mode): 将此添加到您的config/environments/production.rb (如果在生产模式下):

config.action_controller.asset_path = proc { |path| "/mydepartment#{path}" }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM