Rails语法错误:应为关键字end



我得到这个错误:app/views/topics/show.html.erb:49:语法错误,意外的关键字_ensure,应为关键字_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>

可能这一行:

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

你只需要if一次,就像这样:

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

最新更新