我正在尝试在 coffescript 文件中使用 Rails url_helpers。我将 .erb 扩展名附加到文件名 (profile.js.coffee.erb) 并使用 ERB 访问帮助程序,如下所示:
jQuery ->
window.Intl.Models.Profile = Backbone.Model.extend
url: '<%= Intl::Application.routes.url_helpers.profile_path %>'
这在开发中效果很好,它会返回/profile
。在生产中,我使用的是 URL 根目录,/intl
因此我告诉资产预编译器在 deploy.rb 中考虑这一点
set :asset_env, "#{asset_env} RAILS_RELATIVE_URL_ROOT='/intl'"
但是,这似乎不会影响 url_helpers 因为它仍然会返回/profile
而不是/intl/profile
我尝试分别在 production.rb 和 development.rb 中设置 ENV["RAILS_RELATIVE_URL_ROOT"] ,但这也不起作用。
任何建议,将不胜感激。谢谢你。