Topic: error on erb each

undefined method `each' for #<Box:0x23a4884>
Extracted source (around line #3):

1:
2:    
3: <% @box.each do |i| %>
4:
5:             <%= i.city %>
6:

Wa ? I thought that was a given

Re: error on erb each

Ba and in this one I can't even see an each

ndefined method `each' for #<Box:0x22447a0>
Extracted source (around line #1):

1: <% for i in @box %>
2:
3: <%= i.city %>
4:

Re: error on erb each

What is @box exactly? How does it get set?

From your variable naming I would guess that @box isn't a collection and can't be iterated over.

vinnie - rails forum admin

Re: error on erb each

class BoxController < ApplicationController
  # in your controller
  def index
    render :action => 'box'
  end
  def search
   
    @models = Box.find_filtered(params[:keyword], params[:filters]) # replace Model with your own model.
    @box = Box.new
    if request.xml_http_request?
      render :partial => "items_list", :layout => false
    end
   
  end
 

     
end

I swear I spent the weekend re-reading my Agile web book, I re did all of the tutorials in it ,, I just missed something here,,,

Re: error on erb each

class BoxController < ApplicationController
  # in your controller
  def index
    render :action => 'box'
  end
  def search
   
    @models = Box.find_filtered(params[:keyword], params[:filters]) # replace Model with your own model.
    @box = Box.new(params[:filters])
    @box = Box.find(params[:id])
    if request.xml_http_request?
      render :partial => "items_list", :layout => false
    end
   
  end
 

     
end

trying this with no luck either

Re: error on erb each

As vin said, you need a collection to iterate over. What do you expect to happen with @box.each? A @box is just one model object, not a collection of models. Try iterating over your @models variable instead (which should probably be named @boxes).

Railscasts - Free Ruby on Rails Screencasts