Monday, March 21, 2011

Browser reloads again & again with status waiting for localhost but nothing displays in Rails3

Scenario to reproduce the bug: 
Ruby version: ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]

Generated a new rails 3 application with mysql database with command: 
'rails new railsapp -d mysql'

Following are the codes in Gemfile & database.yml file:
Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem 'mysql2'
Development section in database.yml:
development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: railsapp_development
  pool: 5
  username: root
  password:
  host: localhost

Delete index.html located in public folder
Run 'bundle install'.
Run 'rake db:create' to create the db.
Run command 'rails s' to start the server
Open browser and open url 'http://localhost:3000'

You will not see anything on the page except your browser reloads and displays 'waiting for localhost'…No error message will be there in development log file.

To fix the problem, change mysql2 to mysql in Gemfile & database.yml.
Your code should be:
development:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: railsapp_development
  pool: 5
  username: root
  password:
  host: localhost
Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem 'mysql'
Run 'bundle install'
Run command 'rails s' to start the server
Open browser and open url 'http://localhost:3000'
You will see a Routing Error with error as
No route matches "/"

That means, now you are getting response from the server and you can start your development :)

4 comments:

  1. rails 3 (by default) uses the new mysql adapter 'mysql2'. Adapter 'mysql' is the older one and can still be used, but in my view we should go with the flow.

    ReplyDelete
  2. Yes, you are right, rails 3 (by default) uses the new mysql adapter 'mysql2', but 'mysql2' adapter seems to giving problem with Ruby version: 1.8.7 in my application as described above.

    ReplyDelete
  3. I had been struggling with this problem for past 2 days, thank you so much for the help

    ReplyDelete