繁体   English   中英

如何仅在Rails4中的特定子域URL上显示文本?

[英]How could I display text only on a particular subdomain URL in Rails4?

我有一个多租户的Rails 4应用程序。 在测试人员登录“测试”子域帐户之前,我想向他们显示一些说明。 因此,仅应为该特定URL显示文本,而不应为其他子域显示文本。 我该怎么办?

例如,以下是不正确的,但是是我想要实现的示例:

#in devise/sessions/new.html.erb 

<% if url == 'http://test.lvh.me:3000/users/sign_in' %>
  <p>Some text displayed here, just for this subdomain...</p>
  <h2>Sign in</h2>
  ...
<% else %>
  <h2>Sign in</h2>
  ...
<% end %>

您可以使用request.subdomain

<% if request.subdomain == 'test' %>
  <p>Some text displayed here, just for this subdomain...</p>
  <h2>Sign in</h2>
  ...
<% else %>
  <h2>Sign in</h2>
  ...
<% end %>

您可以为该子域使用其他布局。

在您的ApplicationController

  layout :set_layout

  private

  def set_layout
    request.subdomain == 'test' ? 'test' : 'public'
  end

并且在布局中,您可以在<%= yield %>之前添加更多文本。

您可以在此处阅读有关布局的更多信息: http : //guides.rubyonrails.org/layouts_and_rendering.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM