views:

63

answers:

1
 class List
        include DataMapper::Resource

        property :id,         Serial
        property :name,       String
        property :items,      String
    end
    List.auto_migrate!

    get '/:id' do
        @list = List.all(:id => params[:id])
        @items = @list.items
        erb :show
    end

I get undefined method `items' for #. Any ideas?

A: 

You fetch a collection of lists instead of a single list instance, that's why you get the error. I believe you want to do:

@list = List.get(params[:id])
solnic
then I get:NoMethodError at /1undefined method `items' for nil:NilClass
Joel M.
@Joel M: Are you sure that `params[:id]` refers to an actual record? You can use `List.get!` to ensure the record is found, throwing an exception if it is not.
dkubb