首页 > 解决方案 > Rails - Controller route with hostname parameter

问题描述

I have two hosts my application gets deployed to

host1
host2

I want to expose a route that takes a host parameter to connect me to the correlating host. If I call myapp/myendpoint/host1 I want to call the app on host1 and vice versa, but I am struggling to write a route for this. I have tried:

get "controller/:host" => "controller#index"

But now stuck for how to handle the :host parameter in the controller and confirm it has hit the correct host.

标签: ruby-on-rails

解决方案


在控制器中,您可以:host使用params[:host].


推荐阅读