我有一个rails应用程序,它根据查看当前子域的约束来安装几个引擎中的一个。我还想包括一个约束,它查看当前的顶级域,然后在特定的子目录中安装其中一个引擎;例如www.example.com
指向subdirectory.railsapp.com/example
。
这是我当前的routes.rb
:
Rails.application.routes.draw do
mount Accounts::Engine, at: "/"
constraints subdomain: "campaigns" do
mount Petitions::Engine, at: "/"
end
constraints subdomain: "blog" do
mount Blog::Engine, at: "/"
end
constraints subdomain: "events" do
mount Calendar::Engine, at: "/"
end
end
我想添加一个条件,如果域名为www.example.com
,则执行类似mount Petitions::Engine, at: "/example"
的操作。
答案 0 :(得分:1)
您可以使用lambda / proc来实现高级约束(http://guides.rubyonrails.org/routing.html#advanced-constraints):
get '/example', to: 'controller#action',
constraints: lambda { |request| request.host.match /example/ }
request
与您在控制器中获得的request.env
相同。您可以查看request.remote_ip
,constraints(lambda { |request| request.host.match /example/ }) do
mount Petitions::Engine, at: "/example"
end
等。
更多文档:http://apidock.com/rails/v3.2.1/ActionDispatch/Routing/Mapper/Scoping/constraints
t1 = [1476369169.1, 1476369169.2, 1476369169.3, 1476369169.4, 1476369169.5];
TableA = table(t1', [1, 2, 3, 4, 5]', 'VariableNames', {'Time', 'A'});
t2 = [1476369169.1, 1476369169.3, 1476369169.4, 1476369169.5];
PreciseTableB = table(t2', [1, 3, 4, 5]', 'VariableNames', {'Time', 'B'});
PreciseJoin = outerjoin(TableA,PreciseTableB, 'Keys', 'Time', 'MergeKeys', 1)
t4 = t2 + rand(1, 4) / 100;
ErrorTableB = table(t4', [1, 3, 4, 5]', 'VariableNames', {'Time', 'B'});
ErrorJoin = outerjoin(TableA,ErrorTableB, 'Keys', 'Time', 'MergeKeys', 1)