Access table names

Hello,
Anyone know if there is a way to get all of the column names from the
tables usinf rub on rails?
Thanks again

Jack S. wrote:

Hello,
Anyone know if there is a way to get all of the column names from the
tables usinf rub on rails?
Thanks again

yourModel.column_names();

Returns an array of column names as strings.

Jack S. wrote:

Hello,
Anyone know if there is a way to get all of the column names from the
tables usinf rub on rails?
Thanks again

For any table for which you have created a model, you can use the
‘column_names’ class method. eg.

class Person < ActiveRecord::base
end

columns = Person.column_names
=>[“name”,“address”,“id”]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs