更改 Rails 3 开发的基本 URL [英] Changing the base URL for Rails 3 development

查看:37
本文介绍了更改 Rails 3 开发的基本 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

http://localhost:3000/myapp

我想在我的开发环境中为这个部署路径建模.也就是说,我想使用如下所示的基本 URL 进行开发:

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

这样,我可以让我的所有 URL 都相对于/",并且它们将在两种环境中都有效.

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:

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

推荐答案

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

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

尝试在 Rails 'config.ru' 文件中执行此操作:

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

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

现在,当您使用rails 服务器"时,应用程序应该位于 localhost:3000/mydepartment .不确定这是否会给你想要的结果,但值得一试.

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.

这篇关于更改 Rails 3 开发的基本 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆