A
A
Anton2016-04-30 01:52:59
PostgreSQL
Anton, 2016-04-30 01:52:59

How to list all fields and their values ​​in a table?

There is a table. It has notes.
For example, I get the data of this record like this:
@news = News.find(params[:id])
How to display all the keys and their values ​​of this record?
Tried with "each" - didn't work:

undefined method `each'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Demidenko, 2016-04-30
@hummingbird

@news = News.find(params[:id])
@news.attributes.each { |k, v| puts "#{k} - #{v}" }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question