多个公用文件夹,单轨安装

编程入门 行业动态 更新时间:2024-10-27 18:23:29
本文介绍了多个公用文件夹,单轨安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 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

更多推荐

多个公用文件夹,单轨安装

本文发布于:2023-07-12 07:25:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1096853.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单轨   多个   文件夹

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!