我收到了这个特殊的错误: C:/Sites/rails_projects/blog/app/views/posts/index.html.erb:26:语法错误,意外的keyword_ensure,期待keyword_end C:/Sites/rails_projects/blog/app/views/posts/index.html.erb:28:语法错误,意外$ end,期待keyword_end
这里是完整的索引视图
<!DOCTYPE html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<%= will_paginate %>
<% @posts.each do |post| %>
<div class="container", "relative">
<div class="row-fluid">
<h1><%= post.Title %></h1>
<p><%= post.Post %></p>
<% if is_admin? %>
<p><%= link_to 'Show', post %></p>
<p><%= link_to 'Edit', edit_post_path(post) %></p>
<p><%= link_to 'Destroy', post_path(post),
method: :delete, data: { confirm: 'Are you sure?'} %></p>
</div>
</div>
<% end %>
<%= will_paginate %>
<% if is_admin? %>
<%= link_to 'New Post', new_post_path %>
<% else %>
<% end %>
我认为原因是is_admin?
所以这是我的sessions_helper。
def sign_in(user)
cookies.permanent[:remember_token] = user.remember_token
current_user = user
end
def signed_in?
!current_user.nil?
end
def current_user=(user)
@current_user = user
end
def current_user
@current_user ||= User.find_by_remember_token(cookies[:remember_token])
end
def current_user?(user)
user == current_user
end
def is_admin?
signed_in? ? current_user.admin : false
end
def sign_out
current_user = nil
cookies.delete(:remember_token)
end
我不确定错误在哪里?
答案 0 :(得分:0)
<% **@posts.each do |post|** %>
<div class="container", "relative">
<div class="row-fluid">
<h1><%= post.Title %></h1>
<p><%= post.Post %></p>
<% **if is_admin?** %>
<p><%= link_to 'Show', post %></p>
<p><%= link_to 'Edit', edit_post_path(post) %></p>
<p><%= link_to 'Destroy', post_path(post),
method: :delete, data: { confirm: 'Are you sure?'} %></p>
</div>
</div>
<% **end** %>
<%= will_paginate %>
您打开了两个星号块,但只有一个结束语句(也是星号)。