当我读取 DataMapper 中的项目时发生错误

发布于 2024-08-22 20:49:41 字数 374 浏览 1 评论 0原文

 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

我得到 # 的未定义方法“items”。有什么想法吗?

 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

‖放下 2024-08-29 20:49:41

您获取列表的集合而不是单个列表实例,这就是您收到错误的原因。我相信你想做:

@list = List.get(params[:id])

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])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文