How to access sqlite3 tables generated by ruby on rails rvm install - ruby-on-rails

I'm learning ruby on rails by reading the "agile web development with rails" book. I installed ruby and rails using rvm. I'm using the default sqlite3 database, and generating models and tables is awesome.
I'd like to manually browse my db, just to see the structure.
So at the command line is run
sqlite3
and in the shell
.tables
nothing shows up... Where are my tables?

you want to run
rails dbconsole
or
rails db
as it will load your database etc.

For added clarity, the reason ".tables" returned nothing is because you didn't load the database. Start sqlite3 this way:
sqlite3 pathToDatabase/databaseFileName

Related

how to change the database to mongodb from sqlite

I am trying to use the mongodb with ruby on rails
whenever i try to create the new project with
rails new exRuby
preference will be set to sqlite3 in /exRuby/config/database.yml file And automatically "gem 'sqlite3' added to Gem file
But I am trying to use the mongodb with my project. and mongodb is already installed in my system
How to change the database storage to mongodb from sqlite3
Like 'mu is too short' stated, you need to decide which MongoDB interface / gem you want to use to connect to MongoDB. Here is a guide on how to setup a ruby app using Mongoid.
You can run the command rails g mongoid:config to generate the mongoid.yml file. But this is if you choose to use Mongoid. Look at the other gems available and see which one you prefer. Here is a list of available options (according to the MongoDB docs).

Rails error: Couldn't find database client: sqlite3

I'm using Rails in a development environment. I'm trying to run simple INSERT commands via the command line, but I can't seem to connect to the SQLite database. Other database-related commands are working fine (e.g. rake db:migrate). I'm using the following command:
rails dbconsole
But I'm getting the following error:
Couldn't find database client: sqlite3. Check your $PATH and try again.
I'm still learning Rails and I'm hoping you rails Rails experts out there will be able to spot the issue.
Sqlite3 isn't installed on your computer, go to the sqlite site and install the command line utility according to whichever operating system your using.

Why won't my tutorial rails app work?

I'm learning rails with "agile web development with rails (3rd edition)" and I've gotten to the point where I'm supposed to make the depot app.
I have created the depot app, and I've added the script/generate files. I've raked the db. For some reason, no tables where created in the migration and upon running this command:
depot> sqlite3 db/development.sqlite3 "select version from schema_migrations"
I get nothing. Then when running localhost in my browser, instead of getting what I'm supposed to, I get the standard welcome to rails page.
Any advice?
Resolved:
It's always the simple things. Had to direct to localhost:3000/products instead of just to localhost:3000 - wasn't aware of this. Thanks!
There is a number of possibilities here, firstly, judging by the fact you can see the standard "Welcome to Rails" page you haven't deleted public/index.html - you should do this so that Rails can route to the root /
Secondly, if your migrations are running correctly you should have a schema.rb file in ./db with the instructions for each table, if not then something is failing there.
I have not read the 'Agile web development with Rails" book but I am assuming it was written before the release of Rails 3, which means your app does not use Bundler for gem dependency management so it might be worth checking that sqlite3 gem is installed. You can check this with gem list sqlite if you don't see something like "sqlite3-ruby (1.3.2)" then you need to install it.
Lastly, check the log files in ./log/
Well I guess you've created multiple migrations by now so try typing rake db:migrate at the command line and let use know what it says?

Rails error 500 on local mac

Ok, I'm a noob with rails... so I just set up rails with RVM and created a new project, and when I try to visit a newly created view I'm getting an error 500.
Heres my setup:
OSX 10.6.5
Installed MySQL 64bit
RVM installed ruby 1.8.7 and rails 2.3.8 (no other rails or ruby except for the system ruby) rvm install 1.8.7, rvm use --create 1.8.7#rails2, gem install rails -v=2.3.8
Passenger with Apache gem install passenger, rvmsudo passenger-install-apache2-module
Passenger preference pane
Turned on websharing
I then proceeded to setup a rails project in my development folder called testapp, added it in the passenger preference pane, and then ran script/generate controller Say, defined an action hello, and then created a view in the app/view/say folder called hello.
Now I'm getting a 500 error when visiting myapp.local/say/hello, what am i doing wrong?
UPDATE:
I checked the logs and also tried running using WEBrick instead of passenger and apache. I got thrown back the same errors. I don't think I should post the entire log, should I? But the first error is
no such file to load -- sqlite3
I have not yet setup a db, I was going to use mysql, but I didn't want to install it since I'm not using models yet. Is it a requirement?
UPDATE 2:
So I installed the mysql gem with gem install mysql -- --include=/usr/local/lib (not sure if this is right). I then created a rails app with rails -d mysql myapp. And set the password in the database.yml. I'm getting a new error now:
Unknown database 'myapp_development'
So I have to create a database. Why am I being forced to create a db at all?
Yeah, you need to install sqlite even if you're not using models yet - Rails checks to make sure whatever is specified in database.yml is actually there to use.
Don't access it through passenger, launch it using ruby script/server and check out the error it throws there. Generally those errors are way more descriptive than Passenger because Passenger is probably running your application using the production environment.
Hey Ryan, do you need to Ruby 1.8.7? Why don't you install the latest 1.9.2 and Rails 3? I have the same environment and so far no problems. Here is a link for installing everything you need. Let me know if it helped! http://amerine.net/2010/02/24/rvm-rails3-ruby-1-9-2-setup.html
Salud!

How can I host my Ruby on Rails application - no hosting providers offer SQLite3 database

I'm really new at Ruby on Rails development. I'm reading Head First Rails and it says that Rails uses SQLite3 as its database system.
How exactly would I go about uploading my website/application so the world can use it?
Rails uses sqlite3 by default, though you can edit your database.yml file to use a different adaptor (mysql, postgres, etc.) if you'd like. It's not recommended to deploy to production using sqlite3 as your database due to performance issues, though small apps would be ok.

Resources