Rails语法错误:期望关键字结尾

时间:2018-11-28 03:44:18

标签: ruby-on-rails syntax-error

我收到此错误:app / views / topics / show.html.erb:49:语法错误,意外的keyword_ensure,期望的keyword_end。我没有第49行。我检查是否丢失了<%end%>,发现没有。

<h1><%= @topic.name %></h1>

<% if user_is_authorized_for_topics? || if user.moderator? %>
 <%= link_to "Edit Topic", edit_topic_path, class: 'btn btn-success' %>
<% end %>

<% if user_is_authorized_for_topics?%>
 <%= link_to "Delete Topic", @topic, method: :delete, class: 'btn btn-danger', data: { confirm: 'Are you sure you want to delete this topic?' } %>
<% end %>

 <div class="row">
   <div class="col-md-8">
     <p class="lead"><%= @topic.description %></p>
     <% @topic.posts.each do |post| %>
       <div class="media">
         <div class="media-body">
           <h4 class="media-heading">
             <%= link_to post.title, topic_post_path(@topic, post) %>
           </h4>
           <small>
             submitted <%= time_ago_in_words(post.created_at) %> ago by <%= post.user.name %> <br>
             <%= post.comments.count %> Comments
           </small>
         </div>
       </div>
     <% end %>

     <% @topic.sponsored_posts.each do |sponsored_post| %>
      <div class="media">
        <div class="media-body">
          <h4 class="media-heading">
            <%= link_to sponsored_post.title, topic_sponsored_post_path(@topic, sponsored_post) %>
          </h4>
          <small>
            submitted <%= time_ago_in_words(sponsored_post.created_at) %> ago <br>
          </small>
        </div>
      </div>
     <% end %>
   </div>
 <% if current_user %>
   <div class="col-md-4">
     <%= link_to "New Post", new_topic_post_path(@topic), class: 'btn btn-success' %>
   </div>
 <% end %>
 </div>

1 个答案:

答案 0 :(得分:2)

可能这行:

<% if user_is_authorized_for_topics? || if user.moderator? %>

您只需一次if,就像这样:

<% if user_is_authorized_for_topics? || user.moderator? %>