[英]How do I write a conditional to test which page I'm on in Rails?
What I would like to do is to not show the headder in my rails app if the user is on the home page. 我想做的是,如果用户在主页上,则不要在我的rails应用程序中显示标题。 Right now, the header is rendered in this line in application.html.erb:
现在,标题在application.html.erb的以下行中呈现:
<%= render('layouts/header') %>
What I'd like to do is put a conditional so that this doesn't get rendered if I'm on the home page. 我想做的是设置一个条件,这样如果我在主页上就不会显示该条件。 I think it should be something like:
我认为应该是这样的:
<%= render('layouts/header') if not @homepage %>
where I set @homepage to true in the controller for the homepage. 我在主页控制器中将@homepage设置为true。 Does this approach make sense within the rails framework?
这种方法在Rails框架中有意义吗?
有几种方法可以做到这一点,最简单的方法可能是:
<%= render('layouts/header') unless params[:controller] == 'homepage' %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.