Kevin Sun Kevin Sun - 4 months ago 14
Ruby Question

Similar code, but one block show SyntaxError in GroupsController#index

I've two code blocks but one works well and the other one doesn't work.
What happened? This kind of problems have occured seval times, how can I avoid them?

The good one:

<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<a class="navbar-brand" href="/">Rails 101</a>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<% if !current_user %>
<li><%= link_to("註冊", new_user_registration_path) %> </li>
<li><%= link_to("登入", new_user_session_path) %></li>
<% else %>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Hi!, <%= current_user.email %>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li> <%= link_to("登出", destroy_user_session_path, method: :delete) %> </li>
</ul>
</li>
<% end %>

</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>


The one that doesn't work:

<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<a class="navbar-brand" href="/">Rails 101</a>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<% if !current_user %>
<li><%= link_to("注册", new_user_registration_path) %></li>
<li><%= link_to("登入", new_user_session_path %></li>
<% else %>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Hi!, <%= current_user.email %>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to("登出", destroy_user_session_path, method: :delete) %></li>
</ul>
</li>
<% end %>

</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>

Answer

Using a simple text compare tool I can see the second one is missing a ) after new_user_session_path

Free online tool

Comments