0

The following code is a rendering the error: syntax error, unexpected keyword_ensure, expecting $end

<div id="Carousel">
    <% results = @client.search("Twitter", :result_type => "mixed").take(3).to_a %>
    <div class="carousel-inner">
        <div class="active item">
            <p><%= "results[0].text"%></p>
        </div>
        <div class="item">                
            <p><%= "results[1].text"%></p>
        </div>
        <div class="item">
            <p><%= "results[2].text"%></p>
        </div>
    </div>
    <% end %>
</div> 

I honestly have no idea why this is happening. I've tried troubleshooting but I've gotten nowhere. I'm sure it's a little mistake but I can't figure it out. Any help would be very much appreciated.

2
  • 4
    Simply remove the <% end %> line. It's not needed. Commented Apr 5, 2014 at 21:14
  • It worked! Thank you very much. If you don't mind, can you explain why it is not needed? I though that anywhere that I included ERB I had to put a <% end %>. Commented Apr 5, 2014 at 21:18

2 Answers 2

2

As iltempo mentioned this in comment: remove the <% end %> line.

If you don't mind, can you explain why it is not needed?

Because what you do at line 2 is not a block, you just set a variable there that you use later. Example of block:

<% User.all.each do |u| %>
 <%= u.email %>
<% end %>

or

<%= link_to user do %>
 <%= u.email %>
<% end %>
Sign up to request clarification or add additional context in comments.

Comments

1

the stuff between <% %> is ruby code.

<%= %> inserts the result into the html, so for example

<% x = 3 %> will set the ruby variable x to 3 but <%= x = 3 %> will set the ruby variable x to 3 and also insert the value 3 into the html

If you look at what you have in terms of ruby code it is something like this:

results = @client.search("Twitter", :result_type => "mixed").take(3).to_a
"results[0].text"
"results[1].text"
"results[2].text"
end

If you look at that, you will notice the "end" statement is out of place. I also think you probably don't want the "" around the results statements

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.