I would like to view the data in my DB while developing with Rails (actually in all 3 of them development, test and production). I have not touched the configs, so it should
You have neglected to mention the OS you are using.
One way is to use the sqlite3
command in your terminal.
sqlite3 db/development.sqlite3
However, for things like inspecting your rows, you would be better using a rails console.
rails c
> User.all # Where user is your model.
NOTE: Do not change your DB schema directly through sqlite3, something you may be used to if you come from a different web stack background. This is because the next time you run the migrations, the state will be different to what rails expects.
If you are using RubyMine IDE, you can access the sqllite datasource from there. You can run queries or edit data in the database using the GUI.
To view data on DB, I used an SQLite client called DB Browser for SQLite,here is the link
There is a Linux version of this app too. There should be a database file with sqlite
extension on db
directory of the app. On DB Browser, select Open Database option and choose that file and you should be able to view the data.
Rails 3 provides a generic command for accessing the correct database client and pass in the name of the correct database for your current environment. This command is rails dbconsole
which can be shortened to rails db
$ rails db
SQLite version 3.6.12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
This command does not offer much more than Gazler's answer and in fact his advice to use the console is good advice however the plus side for this method is that it will use the correct client if your DB is different in other environments.
use
SQLite> .tables
this will give you the list of all tables exist in the selected database
@@to activate the consol
SQLite> rails dbconsole
@@to show tables
SQLite>.tables
@@ to show all rows in a table
SQLite> select * from posts
There is a great application to browse sqlite3 databases. SQLite Database Browser.
P.S. You mentioned that you are using Aptana studio. I have started my RoR learning with this IDE as well but later have discovered Sublime Text and never wanted to use anything else since, I advise you to check it out.
Cheers