Error happens when I read items in DataMapper
class List
include DataMapper::Resource
property :id, Serial
property :name, 开发者_JAVA技巧 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?
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])
精彩评论