问题
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