【发布时间】:2016-12-27 01:49:39
【问题描述】:
现在,我有它,当用户从collection_select 中选择一个选项时,会根据他们选择的event_id 填充一个 div。根据Event,将显示多个EventOption,每个都有自己唯一的ID。 (我有EventOption 和belongs_to Event,每个has_many。)
这是我在他们选择Event 时通过 JS/Ajax 填充的内容:
<div class="center" >
<h2>Available Options for "<%= @event.name %>":</h2>
<% @event.event_options.each do |e| %>
<p><strong>Name:</strong> <%= e.name %> </p>
<p><strong>Description:</strong> <%= e.description %></p>
<p><strong>Price:</strong> <%= e.price %></p>
</div>
<div class = "center row">
<div class = "col-xs-6">
<%= link_to "Check Available Dates", root_path, :class => "button", :id => "available-dates-button" %>
</div>
<div class = "col-xs-6">
<%= link_to "Book This Event Now!", book_now_path(:event => @event.id), :id => "book-now-button", :class => "button" %>
</div>
<hr>
<% end %>
</div>
我的问题是当他们点击Book This Event Now! 时我可以通过event_id,但这不是我需要的。我需要传递:event_option 的特定:id,我不知道如何从迭代的.each 中获取它。
如何确保我的book_now_path 后面的按钮的每次迭代都有一个唯一的 ID,我可以使用它来完成他们的预订?
【问题讨论】:
标签: ruby-on-rails ruby model-view-controller parameter-passing ruby-on-rails-5