在 Ruby 上显示表中的数据 [英] show data from table on Ruby

查看:31
本文介绍了在 Ruby 上显示表中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Ruby 新手,我正在尝试从表中获取数据.所以当阅读这个

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">]

因此,当我调用 Note.text(例如)时,结果为零.那么我应该在这里写什么来从数组中获取数据?谢谢

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

推荐答案

@note 是一个包含一个 Note 对象的数组.您需要先获取元素.例如:

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

<%= @note.first.text %>

这篇关于在 Ruby 上显示表中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆