インデックスページ内にショーページをポップアップするためにモーダルを使用しています.....製品をクリックするまで、すべてが正常に機能します。何らかの理由で、モーダルのすべての製品に同じ名前が表示されます
私はそれが簡単な修正であることを知っています、助けてください....レールの新機能これは私のコードです:
ビュー
_show.html.erb
<div id="myModal" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="content-inner hero-unit">
<h1 class="pump-up center">
<br>
<strong>Coming Soon.</strong></h1>
<br><br>
<p>
<b>Name: </b>
**<%= @product.name %>**
</p>
</div>
</div>
index.html.erb
<div class="row">
<% @products.each do |product| %>
<div class="span3">
<%= render :partial => 'products/show', :locals => { :product => product } %>
<a href="#myModal" role="button" data-toggle="modal">
<%=(image_tag product.photo(:medium))%></a>
</div>
<% end %>
</div>
モデル
product.rb
class Product < ActiveRecord::Base
attr_accessible :name, :photo
end
コントローラ
products_controller.rb
class ProductsController < ApplicationController
def show
@product = Product.find(params[:id])
end
def index
@products = Product.all
end
end