我正在尝试设置模态的动态数据目标和相应的动态 div id。我遇到了语法错误,但似乎无法找出原因。
我尝试使用“myModal<%= Gift.id %>”作为数据目标和 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 上看到过其他几个类似的问题,但它们似乎不起作用。
谢谢
最佳答案
尝试将 link_中的以下内容更改为“购买”
来自
'data-target' => "#myModal<%= gift.id %>"
至
'data-target' => "#myModal#{gift.id}"
关于ruby-on-rails - 在 Rails 中设置动态数据目标和 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20695391/