Rails error: Couldn't find database client: sqlite3 - ruby-on-rails

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.

Related

PostgreSQL 9.1 and Rails 3 database migration error

I am using PostgreSQL 9.1, which I installed using the DMG provided on the Postgres website. So, my Postgres installation is in /Library/Postgres/9.1.
I am pretty sure my Postgres server is running, but when I run rake db:migrate the rake is aborted with this error:
rake aborted!
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Why is "rake" searching /var/... and not using my installation of Postgres?
Can you supply the link from which you actually downloaded Postgres? It seems like your instance of Postgres has a differently-named socket file than Rails expects, so Rails is unable to find it.
One option is to find the socket that does exist on your system and create a symlink to it from the location mentioned in the output. But my suggestion is to delete this instance of Postgres and simply install it again using Homebrew since you seem to be using OSX. Installation using Homebrew is straightforward: brew install postgresql. After completing the installation just follow the steps listed in the command line output to complete the installation.
Also, if you are using the Postgres.app provided by Heroku you may want to check the documentation.

Rails project using MySQL gem not starting up on Windows 8

My specs are as follow:
Windows 8 64-bit
Ruby 1.9.3
Rails 3.2.12
I installed rails via the RailsInstaller. I have also installed the mysql2 gem. I created a new project that is pre-configured to use mysql e.g.
rails new project_name -d mysql
I then tried to start up the server/WEBrick via
rails server
And I get the following error:
I've tried this using the mysql2 as well as teh mysql gem. Both times I get the same error. When I use the default sqlite then the project starts up fine and I can view it on localhost:3000.
I'm aware that mysql2 used to be a problem on rails, but since mysql isn't working either I'm of the opinion that it's a Windows 8 specific project, surprise surprise.
I'd deff like to use MySQL rather than SQLite. Thanks for anyone that can point me in the right direction!
As a noted error case,
The SO Post says-
"The problem is with mysql. It is a 64 bit installation. Change it to 32bit and it runs fine."
Apart from that, this error may also be the result of some missing gems.
You should try running bundle install before running your server.
Also make sure that gem mysql is added to your gemfile before you do bundle install.
Please update your MySQL to 64bit version. It will fix the problem. Don't forgot to install the Devkit.

"rails server" command is not getting recognized

I am new to rails and am following the tutorial posted on the ROR website. Everything is working fine until I try and load up my rails application on the localhost. Every time enter $ rails server I get a long list of possible commands and functions. When I check my localhost:3000 and 127.0.0.1:3000, nothing seems to be connected.
Upon digging deeper, I have tried almost everything everyone else has tried. I am running the command in the same path as my new rails application. Furthermore, when I enter in nonsense after the $ rails command I get the same list of possible commands and functions. So I get the feeling that rails is not recognizing the server command.
Here are my versions:
Ruby 1.9.3 p374
Rails 3.2.11
Why isn't the server command recognized?
First of all you have to move to the project directory and install bundle with the following command:
bundle install
Then start the server:
rails server
I had the same problem. rails server or simply rails s only works when you are in the right directory.
Type pwd (present working directory) to see where you currently are.
Type cd and the rest of the direction to the correct directory.
(for example, "cd workspace/learn-rails")
Type rails server or rails s.
Check http://localhost:3000.
Please exit from terminal and then restart the terminal.
Then check the directory path i.e just type pwd it will show the current directory path.
And if directory is correct on try again running command like bundle install & rails server
I think this should be work.

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

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

"pg is not part of the bundle. Add it to Gemfile" when not using Postgres

Here's my problem:
I create a new project: rails new myapp.
Rails applications are by default configured to use a SQLite3 database.
I execute bundle exec rake db:create. It works and the SQLite3 database is created.
I try to create a new model (or anything else related to the database), and get the following error:
/home/dinduks/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.3/lib/bundler/rubygems_integration.rb:147:in block in replace_gem': Please install the postgresql adapter:gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.) (LoadError)
When I add a controller and an action, and try to visit it, I get this error:
ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished)
The complete stack trace can be found here: https://gist.github.com/2717365
The WEBrick server starts obviously without complaining.
I reinstalled Rails, reinstalled Ruby, used another Ruby version, reinstalled RVM... And keep getting the same error.
There is nothing related to PostgreSQL, postgres, pg or pql in my code. Not a single word.
I don't want to do what the exception suggests. I want to understand why I have this error and fix it.
So: Why is Rails asking me to install some Postgres stuff while I don't use Postgres?
Thanks!
The problem was the DATABASE_URL environment variable.
When ActiveRecord finds $DATABASE_URL, it automatically uses its information, and ignores config/database.yml.
Thanks to NARKOZ for pointing this out.
(By the way, I had this environment variable set before I discover foreman, which is a great tool to manage environment variables)

Resources