Rick Lloyd wrote:
> views/store/index.html.erb:
> 
> <%= render(:partial => "layouts/test", :object => @array) %>
> 
> views/layouts/_test.html.erb:
> 
> <% for num in test %>
>  <div><%= num %></div>
> <% end %>

Sorry,  I don't know what that means, and I still can't solve my 
original problem, which led to the test code in my op.  Here is what I 
have now:

class StoreController < ApplicationController
  def index
    @products = Product.find(:all)
  end

  def add_to_cart
    @cart = [1, 2, 3]
  end
end


layouts/store.html.erb
-------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>

<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  <title><% @page_title || "Store" %></title>
  <%= stylesheet_link_tag 'scaffold', 'store2.css' %>
</head>
<body>

  <div><%= render(:partial => "cart", :object => @cart) %></div>

</body>
</html>


views/store/_cart.html.erb
-----------------------
<% for num in cart -%>
<div><%= num %></div>
<% end %>


When I go to http://localhost:3000/store in my browser, I get this:
-------------
 NoMethodError in Store#index

Showing app/views/store/_cart.html.erb where line #1 raised:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each

Extracted source (around line #1):

1: <% for num in cart -%>
2: <div><%= num %></div>
3: <% end %>

Trace of template inclusion: app/views/layouts/store.html.erb
------------------

-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to