2
我正在嘗試設置模態和相應的動態div標識的動態數據目標。我被拋出的語法錯誤,但似乎無法找出原因。在Rails中設置動態數據目標和標識
我試圖使用「myModal <%= gift.id%>」作爲data-target和div的唯一名稱。
我得到的錯誤:
/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 ')'
我Index.html.erb頁的樣子:
<%= 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>
我已經看到了SO其他幾個類似這樣的問題,但他們不」似乎工作。
感謝
這完美的作品。謝謝 – Questifer