views/store/index.html.erb:

<%= render(:partial => "layouts/test", :object => @array) %>

views/layouts/_test.html.erb:

<% for num in test %>
 <div><%= num %></div>
<% end %>

On May 8, 5:59 pm, 7stud -- <rails-mailing-l...@andreas-s.net> wrote:
> class StoreController < ApplicationController
>   def index
>     @array = [1, 2, 3]
>   end
>
> end
>
> index.html.erb
> -------------
> render(:partial => "test", :object => @array)
>
> _test.html.erb
> ------------
> <% for num in test %>
> <div><%= num %></div>
> <% end %>
>
> When I enter the url:
>
>    http://localhost:3000/store
>
> in my browser, this is the output:
>
> ---------
> NoMethodError in Store#index
>
> Showing app/views/store/_test.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 test %>
> 2: <div><%= num %></div>
> 3: <% end %>
> -------------------------
>
> The error is saying that test is nil.  A ruby program:
>
> array = [1, 2, 3]
>
> for num in array
>   puts num
> end
>
> --output:--
> 1
> 2
> 3
>
> My understanding was that when you write:
>
>    render(:partial => "test", :object => @array)
>
> then inside the file _test.html.erb a local variable called test is
> assigned the object @array.  But in my application, @array is not
> nil--it was assigned the array [1, 2, 3] in the controller.  Why won't
> rails relent and loop through the array like I am commanding it to do?
> --
> Posted viahttp://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