Show data in table from Rails Console for PostgreSQL
I find something like this: Rails: List of database tables / objects using Rails console?
This line is ok:
ActiveRecord::Base.connection.tables
and returns all tables
but
ActiveRecord::Base.connection.table_structure("users")
generate error:
ActiveRecord::Base.connection.table_structure("projects")
I think that
table_structure
is not a Postgres method.
How can I list all data from a table in the Rails console for a Postgres database?
+3
source to share
1 answer
You can get this information from postgres directly from the command line
psql your_development_database -c "\d"
-- lists all database tables
psql your_development_database -c "\d users"
-- lists all columns for a table; 'users' in this case
If you want to see model attributes in rails console
User.new
User.new.inspect
# or install the awesome_print gem for better output
ap User.new
+9
source to share