0

I have some javascript I would like to execute only if a user is logged into my rails app. I set up the user show page as follows:

<table class="profile" summary="Profile information">
  <tr>
    <td class="main">
      <h1>
        <%= gravatar_for @user %>
        <%= @user.name %>
      </h1>
      <%= render 'follow_form' if signed_in? %>
      <% end %>
    </td>
    <td class="sidebar round">
      <strong>Name</strong> <%= @user.name %><br />
      <strong>URL</strong> <%= link_to user_path(@user), @user %><br />
    </td>
  </tr>
</table>


<% if signed_in? %>

<div id="app-body">
<script type="text/javascript">
document.write("Hello World")
</script>
</div>

 <% end %>

where signed_in? is a convenience method that returns a boolean if a user is logged in or not. The issue is when I try to load this page I get an error at one line past the end of the file:

syntax error, unexpected keyword_ensure, expecting $end

Extracted source (around line #48):

45: </div>
46: 
47:  <% end %>

Does anyone know how I can fix this error? All I find when I search are HAML indentation issues, but here I am using erb, so indentation shouldn't matter.

2
  • 2
    as per your code, nothing is wrong. Can you check in your erb file if any block is not ended properly. Commented Feb 28, 2012 at 4:51
  • I updated my code to show the entire page, I believe all the blocks are closed. Commented Feb 28, 2012 at 5:01

1 Answer 1

1

there is an extra end in your code after <%= render 'follow_form' if signed_in? %> remove it.

In ruby no need to have end statement for condition at end of line so <% end %> is not needed for <%= render 'follow_form' if signed_in? %>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.