I am attempting to use an object’s parameter in a link_to as follows:
<% @step.images.each do |pic| %>
<script>
alert(<%=pic.id%>);
</script>
<li class = "span2" id="picture_<%=pic.id %>">
<div class="thumbnail">
<%=image_tag(pic.url.to_s, :width => "100%") %>
<p style="text-align: center;">
<!-- ERROR ON LINE BELOW FOR LINK_TO PATH -->
<%= link_to edit_step_image_path("<%=pic.id%>"), :class=> "btn btn-mini" do %>
<i class="icon-edit"></i>
<% end %>
<a href="#" class="btn btn-mini btn-delete" confirm="Are you sure you want to delete this photo?" data-method="delete">
<i class="icon-trash"></i>
</a>
</div>
</li>
<% end %>
I checked that my alert does pass the right id, but when I attempt to use the pic.id in my link_to, I get a syntax error. Removing the parenthetical around <%=pic.id%> gets rid of the error but gives me the wrong id.
How might I fix this?
You’re trying to interpolate ERB inside ERB, which just won’t work. You’re already in Ruby code, so just write Ruby! Instead use this: