我正在使用模式来弹出索引页面内的显示页面.....一切正常,直到我开始在我的节目中使用@ product.name页面部分。渲染显示页面,在我的索引页面通过模式
我得到这个错误:
undefined method `name' for nil:NilClass
我知道这是一个简单的办法,请大家帮忙....新轨道 这是我的代码:
查看
_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
<%= render :partial => "show", :locals => { :product => @product } %>
<div class="row">
<% @products.each do |product| %>
<div class="span3">
<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
你好浪涌你是怎么解决“不同产品上的同名产品问题”的? – learner 2015-05-03 04:11:01