I am using a model to pop up the show page inside the index page ..... my Start using partial @ product.name in the show page.
I get this error:
'Names' for the undefined method zero: NilClass I know this is a Easy fix, please help ... This is my code for Rail:
View _show.html .erb
and & Lt; Strong & gt; Coming soon. & Lt; / Strong> & Lt; / H1> & Lt; Br> & Lt; Br> & Lt; P & gt; & Lt; B & gt; Name: & lt; / B & gt; ** & lt;% = @ product.name% & gt; ** & lt; / P & gt; & Lt; / Div & gt; & Lt; / Div & gt;
index.html.erb
& lt;% = render: partial = & gt; "Show",: Local => {: Product = & gt; @ Productive}%> & Lt; Div class = "row" & gt; & Lt;% @ products.each do | Products | & Gt%; & Lt; Div class = "span3" & gt; & Lt; A href = "# myModal" role = "button" data-toggle = "model" & gt; & Lt;% = (image_tag product.photo (Medium))% & gt; & Lt; / A & gt; & Lt; / Div & gt; & Lt;% end% & gt; & Lt; / Div & gt; Model product.rb
class product & lt; ActiveRecord :: Base attr_accessible: name,: photo end controller products_controller.rb
Class Product Controller & lt; ApplicationController def Show @ Product = Product.Fund (Parameters [: ID]) End Def Index = Products = Product.All End End
You are providing the index template with the index operation in your scope so that @product < Code> none . You must present partially in the loop with each product. index.html.erb should be something like this: & lt; Div class = "row" & gt; & Lt;% @ products.each do | Products | & Gt%; & Lt; Div class = "span3" & gt; & Lt;% = Render: Partial = & gt; "Show",: Local => {: Product = & gt; Product}%> & Lt; A href = "# myModal" role = "button" data-toggle = "model" & gt; & Lt;% = (image_tag product.photo (Medium))% & gt; & Lt; / A & gt; & Lt; / Div & gt; & Lt;% end% & gt; & Lt; / Div & gt;
Comments
Post a Comment