我有一个文件存储在public/ads.txt
中ads.txt
可以通过mywebsiteurl.com/ads.txt
访问
但是我也希望使用本地参数访问此文件,例如mywebsiteurl.com/en/ads.txt
路线.rb
Rails.application.routes.draw do
get 'ads.txt', to: redirect("/ads.txt")
scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do
resources :offers
...
end
end
当本地参数存在时.txt我该如何访问广告?(我试图将获取"ads.txt"路由放在我的 :locale 范围内,但它不起作用。有什么想法吗?
你真的不需要get 'asd.txt'
路由重定向,网络服务器(nginx,apache等(应该从/public提供文件,而无需接触你的rails应用程序。
对于您的实际问题,您应该能够这样做:
scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do
get 'asd.txt', redirect_to('/asd.txt') # this should match ":local/asd.txt" request
resources :offers
...
end