更改 Rails 3 开发的基本 URL

发布于 2024-10-30 18:28:51 字数 780 浏览 1 评论 0原文

我知道我将部署到一个环境,其中我的应用程序使用基本 URL 运行,如下所示:

http://someserver/mydepartment/myapp

我的开发环境设置为使用默认的 Rails 配置,如下所示:

http://localhost:3000/myapp

我想对此部署进行建模我的开发环境中的路径。也就是说,我想使用如下所示的基本 URL 进行开发:

http://localhost:3000/mydepartment/myapp

这样,我可以使所有 URL 相对于“/”,并且它们将在两种环境中工作。

我该如何更改它,以便我的应用程序能够在我的开发环境中运行在这条路径上?

我找到的解决方案,但对我不起作用:

  • routes.rb 中设置 scope 似乎不适用于 public 中的静态内容
  • 使用 Apache 的重写功能。我不想在我的开发盒上安装 Apache。理想情况下,该解决方案可以与 WEbrick 一起使用,尽管我似乎 Mongrel 也能大部分工作(Mongrel 和 Ruby 1.9.2 存在一些问题)。
  • 设置 relative_url_root 和类似的建议不适用于 Rails 3。
  • 动态生成 CSS/JavaScript 并调整路径以在开发和生产环境之间进行补偿。

I know I'm going to deploy to an environment with my application running with a base URL which looks like this:

http://someserver/mydepartment/myapp

My development environment is set up to use the default Rails configuration, which looks like this:

http://localhost:3000/myapp

I'd like to model this deployment path in my development environment. That is, I'd like to develop with a base URL which looks like this:

http://localhost:3000/mydepartment/myapp

That way, I can make all my URLs relative to "/" and they will work in both environments.

How can I change it so my application will live at this path in my development environment?

Solutions I've found, but don't work for me:

  • Setting the scope in routes.rb doesn't seem to work for the static content in public.
  • Using Apache's rewriting capabilities. I don't want to install Apache on my development box. Ideally the solution would work with WEbrick, though I seem to have Mongrel mostly working as well (there are some problems with Mongrel and Ruby 1.9.2).
  • Setting relative_url_root and similar suggestions which don't work with Rails 3.
  • Dynamically generating CSS/JavaScript and adjusting the paths to compensate between development and production environments.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘿哥们儿 2024-11-06 18:28:51

您可以尝试将 Rails 应用程序机架配置映射到不同的 base_uri。
您需要做的就是将现有的“运行”命令包装在地图块中,

尝试在您的 Rails“config.ru”文件中执行此操作:

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

现在,当您“rails 服务器”时,应用程序应该位于 <强>本地主机:3000/mydepartment。
不确定这是否会给您带来预期的结果,但值得一试。

You can try mapping your rails app rack config to a different base_uri.
All you need to do is wrap the existing 'run' command in a map block

try doing this in your rails 'config.ru' file:

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

Now when you 'rails server' the app should be at localhost:3000/mydepartment .
Not sure if this will give you the desired outcome, but worth a try.

歌枕肩 2024-11-06 18:28:51

以下是如何将 Rails 3.1 应用程序部署到 Apache 中的子目录,替换不再存在的 config.action_controller.relative_url_root

config/routes.rb 中:

scope 'my_subdir' do
  # all resources and routes go here
end

在 Apache 配置文件中:

Alias /my_subdir /var/www/my_subdir/public
<Location /my_subdir>
  SetEnv RAILS_RELATIVE_URL_ROOT "/my_subdir"
  PassengerAppRoot /var/www/my_subdir
</Location>

它应该可以工作,包括自动将所有资产指向 /my_subdir

Here’s how you can deploy a Rails 3.1 app to a subdirectory in Apache, replacing config.action_controller.relative_url_root which no longer exists.

In config/routes.rb:

scope 'my_subdir' do
  # all resources and routes go here
end

In your Apache configuration file:

Alias /my_subdir /var/www/my_subdir/public
<Location /my_subdir>
  SetEnv RAILS_RELATIVE_URL_ROOT "/my_subdir"
  PassengerAppRoot /var/www/my_subdir
</Location>

And it should work, including automatically pointing all your assets to /my_subdir.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文