Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
594 views
in Technique[技术] by (71.8m points)

Changing the base URL for Rails 3 development

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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...