服务器前缀和rails路线
使用路径选项启动服务器时
script/server --path=/myapp
当我在有路由的情况下
map.route 'foo', :controller => 'bar', :action => 'buzz'
,会
ActionController::Routing::Routes.recognize_path('/myapp/foo')
引发错误“没有匹配的路由...”
问题:如何使 Rails 内置路由识别路径前缀? 多谢!
When i'm starting the server with the path option
script/server --path=/myapp
while having a route
map.route 'foo', :controller => 'bar', :action => 'buzz'
then
ActionController::Routing::Routes.recognize_path('/myapp/foo')
raises an error "No route matched ..."
Question: How can i make Rails built-in routing recognize with path prefix?
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将 config.action_controller.relative_url_root = "/myapp" 放入environments.rb 中并正常启动服务器。
然后 Rails 会将 /myapp/ 附加到你的所有路由中
Try putting
config.action_controller.relative_url_root = "/myapp"
in environments.rb and start your server normally.Then Rails will append /myapp/ to all your routes
实际上有一个 path_prefix 可用于路由,因此您可以执行以下操作:
这应该为您提供 /myapp/foo 的路由
There is actually a path_prefix available for routes so you can do something like this:
That should give you a route for /myapp/foo
非常感谢你的回答!
不幸的是,我无法在
map.foo
中使用:path_prefix
选项,因为情况并非总是如此(最终用户应该负责设置或不设置前缀,而不用担心任何路线)。我指出以下内容:
thanks a lot for your answers!
unfortunately i can't use the
:path_prefix
option inmap.foo
, because it's not always the case (the end-user should be responsible for setting or not the prefix while not worring about any routes).i fingered out following: