show data from table on Ruby

与世无争的帅哥 提交于 2020-02-06 06:16:09

问题


I am new on Ruby and I am trying get data from table. so when read this

<%= puts @note.inspect %> I have this this result.

[#<Note id: 1, user_id: 1, note_type: 0, text: "Barev dzez", lat: 40.2290542420142, lng: 44.420879046875, deleted: false, created_at: "2012-04-26 14:10:05", updated_at: "2012-04-26 14:10:05">]

So when I call Note.text (for instance) I got nil result. So what should I write here to get data from array? Thanks


回答1:


@note is an Array with one Note object. You need to get the element first. For example:

<%= @note.first.text %>



回答2:


You are retrive record in an array so you need to call like this

      <%= puts @note.first.text %>

or

      <%= puts @note.last.text %>    if there is only one record 

But you don't specify how you are retrive records..



来源:https://stackoverflow.com/questions/10346140/show-data-from-table-on-ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!