Kevin Sun Kevin Sun - 4 months ago 6
Ruby Question

two completely same coding ,one works well ,the other one doesn;t ,shows SyntaxError in GroupsController#index

i've two code blocks but one works well,the other one doesn't work,what happened? this kind of problems have occured for seval times ,how can i avoid them?is there some advice?

The good one as:

<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 not-work one as:

<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