Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 什么';在多语言Rails应用程序中重定向控制器操作的最佳方法是什么?_Ruby On Rails_Ruby_Routes - Fatal编程技术网

Ruby on rails 什么';在多语言Rails应用程序中重定向控制器操作的最佳方法是什么?

Ruby on rails 什么';在多语言Rails应用程序中重定向控制器操作的最佳方法是什么?,ruby-on-rails,ruby,routes,Ruby On Rails,Ruby,Routes,在我的多语言Rails 5应用程序中,将类似www.myapp.com/things的URL转发到www.myapp.com/things/new的最佳方式是什么 这是我的routes.rb文件: Rails.application.routes.draw do scope "(:locale)", :locale => /#{I18n.available_locales.join("|")}/ do resources :things, :only => [:new

在我的多语言Rails 5应用程序中,将类似
www.myapp.com/things
的URL转发到
www.myapp.com/things/new
的最佳方式是什么

这是我的
routes.rb
文件:

Rails.application.routes.draw do

  scope "(:locale)", :locale => /#{I18n.available_locales.join("|")}/ do

    resources :things, :only => [:new, :create]

  end

end
我尝试在routes文件中执行此操作:

get '/things', :to => redirect('/things/new')
但是,我无法使用
区域设置

ThingsController中执行此操作确实有效

def index
  redirect_to new_thing_path
end
。。。但似乎是错误的,因为我必须在我的
路由
文件中创建
索引
操作


谢谢你的帮助

“我无法使用
区域设置
”是什么意思?您可以发布任何错误吗?如果在重定向中包含区域设置,会发生什么情况
to:redirect('/%{locale}/things/new')
我猜为什么在这里似乎是一个有效的问题。如果您知道RESTfully
/things
应该是一个“索引”操作,而您没有索引操作,那么为什么您要为“/things”创建一个路由呢?@SimpleTime因为它不工作,所以什么也不会发生。我用的代码和你的一样。这就是我所说的
locales
@engineerinesmnky实际上是一个很好的观点。我想我的应用程序应该尽可能友好。在我的应用程序中,人们倾向于经常使用URL。我会说让他们“随意使用”,但404仍然是404,例如,你是否应该考虑“/thing”和“/stuff”以及“[/]你也说Froderick吗?”?如果他们输入的路径无效,那么404不是比“你在找我吗?”路由模式更合适吗?最多我会建议使用一个全包路由并重定向到root(可能会有一条闪光消息?)