0
votes

I get this particular error: C:/Sites/rails_projects/blog/app/views/posts/index.html.erb:26: syntax error, unexpected keyword_ensure, expecting keyword_end C:/Sites/rails_projects/blog/app/views/posts/index.html.erb:28: syntax error, unexpected $end, expecting keyword_end

Right here is the full index view

    <!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 %>

I think the reason is the is_admin?

So here is my 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

I'm not exactly sure where the error is?

1
try (signed_in? ? current_user.admin : false) but it is not the function - Малъ Скрылевъ
show your full index view - Малъ Скрылевъ
Just uploaded it, I get syntax error but I'm not sure where it'd be from. - google1254
Your posts.each and if admin statement right after <p><%= post.Post %></p> needs to be closed with an end, you only have one. - Saifis
should tab more meticulously to avoid missing closing blocks, believe me I would know. - Saifis

1 Answers

0
votes
<% **@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 %>

There are two asterisk'd blocks that you opened but only one end statement (also asterisk'd).