开发者

Error happens when I read items in DataMapper

开发者 https://www.devze.com 2022-12-21 06:33 出处:网络
class List include DataMapper::Resource property :id,Serial property :name,开发者_JAVA技巧 String property :items,String
 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])
0

精彩评论

暂无评论...
验证码 换一张
取 消