Reputation: 371
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.
Upvotes: 0
Views: 93
Reputation: 16748
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
Upvotes: 1
Reputation: 11421
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 %>
Upvotes: 2