开发/生产环境下申请root url的路由问题
我的应用程序在路由方面存在问题。在生产中,根网址是 example.com/xyz/
并且很多 images_paths 被设置为 ../xyz/assets/header.jpg
在开发中,我正在接收路由错误,因为我的主机是 localhost:3000。我想要实现的目标类似于 localhost:3000/xyz ,以便路由路径再次适合。生产路线应保持不变。
开发环境中当前的错误消息是:
ActionController::RoutingError (No route matches [GET] "/xyz/assets/header.jpg"):
Cant I use things like this in my application_controller?
Rails.application.routes.default_url_options[:host]= 'localhost:3000/xyz'
谢谢建议
I have a problem on my application concerning routing. In production the root url is example.com/xyz/
And a lot of images_paths are set to ../xyz/assets/header.jpg
In development I am receiving routing errors, since my host is localhost:3000
. What I am trying to achieve is something like localhost:3000/xyz
so the routing paths fit again. Production routes should stay the same.
Current error message in development environment is:
ActionController::RoutingError (No route matches [GET] "/xyz/assets/header.jpg"):
Cant I use something like this in my application_controller?
Rails.application.routes.default_url_options[:host]= 'localhost:3000/xyz'
Thx for advise
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用类似的内容构建文件路径,
实际上,自 Rails 3 以来不推荐使用 RAILS_ROOT,因此您现在应该使用,
祝您好运!
You can construct a file path with something like,
Actually, RAILS_ROOT is deprecated since Rails 3, so you should now use,
Good luck!