我有一个 Rails 应用程序,我想用于多个站点,每个站点都有不同的设计.
I have a rails application I would like to use for multiple sites, each with different designs.
我想将 rails 安装/public 目录更改为其他内容(最终动态).但是,我遇到了一个问题(错误?)更改目录...
I would like to change the rails installation /public directory to something else (dynamically eventually). However, I have run into a problem (bug?) changing directories...
在我的 application.rb 文件中,我将 paths.public 路径更改为public"以外的其他路径(假设为site_one").代码如下:
In my application.rb file I change the paths.public path to something other than "public" (let's say "site_one"). Here is the code:
puts paths.public.paths paths.public = "site_one" puts paths.public.paths两个puts"命令用于调试.现在运行rails s",你会看到:
The two "puts" commands are for debugging. Now run "rails s" and you will see:
/home/macklin/app/public /home/macklin/app/site_one这将验证路径是否正确更改.但是,不久之后,rails 抛出以下错误(如果您需要完整跟踪,请告诉我):
This verifies the path is changed correctly. However, shortly afterward, rails throws the following error (let me know if you need the full trace):
Exiting /usr/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/paths.rb:16:in `method_missing': undefined method `javascripts' for #<Rails::Paths::Path:0x7f422bd76f58> (NoMethodError) from /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.3/lib/action_controller/railtie.rb:47我的猜测是它找不到 javascripts 目录,即使它显然位于site_one"文件夹中.
My guess is it cannot find the javascripts directory even though it is clearly sitting in the "site_one" folder.
有谁知道我为什么会得到这个?
Does anyone know why I am getting this?
推荐答案我知道这个问题很老了,但我想我在 Rails 4.2 中找到了答案.
I know this question is pretty old, but I think I found an answer for this in Rails 4.2.
您只需将此行放在您的 config/application.rb 中:
You just simply have to put this line in your config/application.rb:
middleware.use ::ActionDispatch::Static, "#{Rails.root}/another_public_folder_name", index: 'index', headers: config.static_cache_control这使得 /another_public_folder_name 中的所有文件都由 Rails 提供服务.
This makes all files in /another_public_folder_name to be served by Rails.
这是 Rails 用来设置标准 /public 文件夹的方式.我发现它检查来源:
This is the way Rails use to setup the standard /public folder. I found it checking the sources:
github/rails/rails/blob/52ce6ece8c8f74064bb64e0a0b1ddd83092718e1/railties/lib/rails/application/default_middleware_stack.rb#L24
更多推荐
多个公用文件夹,单轨安装
发布评论