Skip to content

Instantly share code, notes, and snippets.

@between40and2
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save between40and2/3ba79b367a8860ddb5f1 to your computer and use it in GitHub Desktop.
Save between40and2/3ba79b367a8860ddb5f1 to your computer and use it in GitHub Desktop.
You can do a lot of things in rails console. Here we just tip on migration part.

How database/table related info

Account.table_name
Account.columns.collect {|x| x.name}

Change table structure

Even you can do rails g migration in cli, which is also persisted to share. Here is a quick and dirty way.

ActiveRecord::Migration.remove_column :framework_classes, :field123

See API: ActiveRecord::ConnectionAdapters::SchemaStatements

Show the data/content

Account.all

Operate on the data record

Reload!

You may need to reload the tables or models after change. But you may also find that there is no such method in ActiveRecord. The solution is to reload the console, by

> roload!

See Here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment