Rails应用程序中的前缀URL

时间:2011-01-16 20:39:35

标签: ruby-on-rails routing

我希望我的2.3 Rails应用程序中的所有页面都有以前缀为:

的网址
www.example.com/app/

我在routes.rb写了以下几行:

# I named the first part of the url ':appl'
map.root :appl => "app", :controller => "home"

# Default routes
map.connect ':appl/:controller/:action/:id'
map.connect ':appl/:controller/:action/:id.:format'

一切正常,map.resources除外,我有

map.resources :pages

现在无论我有edit_page_path还是page,生成的网址都不正确,因为app未在开头插入。我尝试使用namespacescope,就像我见过here in chapter 2.6一样,但没有成功。

我该怎么做?路线中的:appl是个坏主意吗?

2 个答案:

答案 0 :(得分:6)

如果要在Passenger上部署,则只需设置(在您的网络服务器配置中):

RailsBaseURI /app

然后在你的应用程序配置中:

config.action_controller.relative_url_root = '/app'

除此之外,你不应该担心任何次级的东西。它应该工作。有关详细信息,请参阅Passenger documentation

对于mongrel,您可以使用--prefix选项

script/server mongrel -P /app

答案 1 :(得分:0)

这是我在routes.rb写的:

map.resources :pages,   :as => 'app/pages'

现在,edit_page_path和其他人返回正确的路径,前缀为'app'