twitter bootstrap - Rails: Choosing an object on button click and showing info on modal -


i have long list of cats in database

cat(id: integer, name: string, gender: integer, home: boolean, created_at: datetime, updated_at: datetime) 

and on web page wish open bootstrap modal information of 1 cat in it. id of cat determined on button click. in catscontroller have defined

def index  @cats = cat.all end 

and path /cats/ shows

<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#mymodal"> open modal </button>    <div class="modal fade" id="mymodal" role="dialog">     <div class="modal-dialog">       <!-- modal content-->       <div class="modal-content">         <div class="modal-header">           <button type="button" class="close" data-dismiss="modal">&times;</button>           <h4 class="modal-title">modal header</h4>         </div>         <div class="modal-body">           <p>some text in modal.</p>         </div>         <div class="modal-footer">           <button type="button" class="btn btn-default" data-dismiss="modal">close</button>         </div>       </div>     </div>   </div> 

how can done rails way?

make loop iterate on cats , in loop body include modal , button .

inside button put :

data-target="#mymodal_<%=cat.id%>"> 

and inside modal put a

 id="mymodal_<%=cat.id%>" 

i'm afraid matter of client side , rails more server oriented .


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -