user1796260
user1796260

Reputation: 297

Rails how to make dynamic modal window using twitter bootstrap

Hi every one I'm starting using twitter bootstrap with rails and I would like to make a modal window for each events but the modal window is the same for each component

I've this code :

<% @event.each do |event| %>
  <div class="modal hide fade" id="infos">
    <div class="modal-header"> 
      <a class="close" data-dismiss="modal">×</a>
      <h3><%= event.titre %></h3>
    </div>
    <div class="modal-body">
      <p><%= event.titre %><%= event.dday %><%= event.lieux %> <%= event.commentaire%></p>
    </div>
  </div>
  <div class="timeline_event" data-toggle="modal" data-target="#infos">
    <%= link_to (event.titre), event %> <br />
    <p>Le <%= event.dday %> à <%= event.lieux %></p>
   </div>
<% end %>

Upvotes: 0

Views: 1060

Answers (1)

ck3g
ck3g

Reputation: 5929

You have same id for all divs. So the first modal are always opens. Try to set unique ids:

<div class="modal hide fade" id="<%= dom_id(event, :infos) %>">
...
<div class="timeline_event" data-toggle="modal" data-target="#<%= dom_id(event, :infos) %>">

upd: http://apidock.com/rails/ActionController/RecordIdentifier/dom_id

Upvotes: 2

Related Questions