NoMethodError when I try to acces a field of an object taken from the DB

前端 未结 4 1669
[愿得一人]
[愿得一人] 2021-01-25 20:19

  Let\'s say that I have a model called Tweet with the following fields

  • 1. id
  • 2. content
  • 3. created_at
  • 4. user_id
  • <
4条回答
  •  心在旅途
    2021-01-25 20:47

    In your case, It returns a collection of object of Active Record Relation

    so for specific record

    @original.first.id gives you 64

    or

      @tweet = Tweet.find(64)
      @tweet.id #64
      @tweet.content # "Unde et nisi blanditiis vel occaecati soluta praes..."
    

提交回复
热议问题