Question

I am trying to set a dynamic data-target of a modal and a corresponding dynamic div id. I'm being thrown syntax errors but can't seem to find out why.

I'm trying to use "myModal<%= gift.id %>" as the unique name for the data-target and div.

The error I am getting:

/Users/bvlaar/Sites/Redwood/app/views/gifts/index.html.erb:12: syntax error, unexpected $undefined, expecting '}'
... :class => "btn btn-primary", \'data-type\' => "html" } %></...
...                               ^
/Users/bvlaar/Sites/Redwood/app/views/gifts/index.html.erb:25: syntax error, unexpected keyword_end, expecting ')'
';       end 
            ^
/Users/bvlaar/Sites/Redwood/app/views/gifts/index.html.erb:32: syntax error, unexpected keyword_ensure, expecting ')'
/Users/bvlaar/Sites/Redwood/app/views/gifts/index.html.erb:34: syntax error, unexpected keyword_end, expecting ')'

My Index.html.erb page looks like:

<%= title "Redwood | Gifts" %>
<div class="container">
    <div class="row">
        <% @gifts.each do |gift|  %>
        <div class="col-sm-6 col-md-4">
            <div class="thumbnail">
                <%= image_tag gift.picture.url(:medium) %>
                <div class="caption">
                    <h3><%= gift.name %></h3>
                    <h4><%= gift.merchant.name %></h4>
                    <p><%= gift.description %></p>
                    <p><%= link_to 'Buy', gift_path(gift), { :remote => true, 'data-toggle' =>  "modal", 'data-target' => "#myModal<%= gift.id %>", :class => "btn btn-primary", 'data-type' => "html" } %></p>
                </div>
                <!-- Modal -->
                    <div class="modal fade" id="myModal<%= gift.id %>">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <%= render partial: 'show', :locals => { :gift => gift } %>
                            </div>
                        </div>
                    </div>
                <!-- End of Modal -->
            </div>
        </div>
        <% end %>
    </div>
</div>

I've seen several other questions like this on SO, but they don't seem to be working.

Thanks

Was it helpful?

Solution

try changing the following in link_to 'Buy'

from

'data-target' => "#myModal<%= gift.id %>"

to

'data-target' => "#myModal#{gift.id}"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top