语法错误,意外的keyword_ensure,期待keyword_end

时间:2015-07-13 09:08:08

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4

我目前在我的_header中有3个循环

if current_user.admin? && !current_user?(user) 

另外

<% if logged_in? %>

并且

<% else %>

如果我拿出

,一切正常,没有错误
<% if current_user.admin? && !current_user?(user) %>
  <li><%= link_to "Admin", users_path %></li>
</end>

当我将其粘贴回来时,我得到了错误。我不知道这种语法有什么问题。

有人可以帮忙吗?

    <ul class="nav navbar-nav navbar-right">   
        <% if current_user.admin? && !current_user?(user) %>
          <li><%= link_to "Admin", users_path %></li>
        </end>
        <% if logged_in? %>
          <li><%= link_to "Dash", users_path %></li>
          <ul class="nav navbar-nav">
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Items<span class="caret"></span></a>
              <ul class="dropdown-menu">
                <li><%= link_to "New Item", new_item_path %></li>
                <li><%= link_to "Edit Items", user_items_path %></li>
                <li><a href="#">Mass Upload Items</a></li>
                <li><a href="#">Upload Item Images</a></li>
              </ul>
            </li>
          </ul>
          <ul class="nav navbar-nav">
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Profile<span class="caret"></span></a>
              <ul class="dropdown-menu">
                <li><%= link_to "View Profile", user_path(current_user) %></li>
                <li><%= link_to "Edit Profile", edit_user_path(current_user) %></li>
              </ul>
            </li>
          </ul>
          <li><%= link_to "Messages", users_path %></li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Settings<span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#">Edit Money Back Policies</a></li>
              <li><a href="#">Edit Warranty Policies</a></li>
            </ul>
          </li>
          <li><%= link_to "Log out", logout_path, method: "delete" %></li>
        <% else %>
          <li><%= link_to "Log In", login_path %></li>
          <li><a href="#">Sign Up</a></li>
        <% end %>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</header>

4 个答案:

答案 0 :(得分:1)

您未正确关闭粘贴的if

    <% if current_user.admin? && !current_user?(user) %>
      <li><%= link_to "Admin", users_path %></li>
    </end>

您应该尝试通过以下方式替换它:

    <% if current_user.admin? && !current_user?(user) %>
      <li><%= link_to "Admin", users_path %></li>
    <% end %>

答案 1 :(得分:0)

if循环中的if循环结构在if循环的ruby.your结束标记中是错误的。请参阅下面的

<%if%>
   //condition here
<%end%>

答案 2 :(得分:-1)

你能尝试一下吗?

<% if logged_in? && !current_user?(user) && current_user.admin?  %>
  <li><%= link_to "Admin", users_path %></li>
</end>

答案 3 :(得分:-1)

关闭if block syntex时出现Syntex错误。

1 <% if current_user.admin? && !current_user?(user) %>
2   <li><%= link_to "Admin", users_path %></li>
3 </end> 

第3行出错,替换第3行,即</end> with <% end %>