【发布时间】:2014-11-10 19:58:25
【问题描述】:
我在 html.erb 中遇到了 if、elsif、else 语句的问题。我在 erb 中看到了很多关于 if/else 语句的问题,但没有一个包含 elsif,所以我想我会寻求帮助。
这是我的 html.erb:
<% if logged_in? %>
<ul class = "nav navbar-nav pull-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Account <b class="caret"></b>
</a>
<ul class="dropdown-menu pull-right">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
<li class="divider"></li>
<li>
<%= link_to "Log out", logout_path, method: "delete" %>
</li>
</ul>
</li>
</ul>
<% elsif has_booth?(current_user.id) %>
<ul>
<li>TEST</li>
</ul>
<% else %>
<ul class="nav navbar-nav pull-right">
<li><%= link_to "Sign Up", signup_path %></li>
<li><%= link_to "Log in", login_path %></li>
</ul>
<% end %>
这是我的 has_booths 方法:
module BoothsHelper
def has_booth?(user_id)
Booth.exists?(user_id: user_id)
end
end
我希望标题导航为不同的用户提供三种不同类型的内容。已登录用户、已创建展位的已登录用户和已注销用户。到目前为止,我似乎只能完成三项工作中的两项。我尝试改变
<% elsif has_booth?(current_user.id) %>
到
<% elsif logged_in? && has_booth?(current_user.id) %>
这也不起作用。我的陈述是否正确?任何想法表示赞赏。谢谢。
【问题讨论】:
标签: ruby-on-rails-4 erb