0

I'm trying to use the generate script to create a controller. I run the following command:

> ruby script/generate controller Greeting

and the controller seems to be generated no problem. Then I add a method called index to the GreetingController:

class GreetingController < ApplicationController
  def index
    render :text => "<h1>Welcome to your first Rails application<h1>"
  end
end

I then start the WEBrick web server, and direct my browser to http://127.0.0.1:3000/greeting, but I get an error message in the browser saying:

We're sorry, but something went wrong.

We've been notified about this issue and we'll take a look at it shortly.

It should be working, at least according to the book I'm reading, Ruby on Rails by O'Reilly. Any idea what could be going wrong? The book was written a few years back, and I'm using what's probably a newer version or Rails. Any ideas?

UPDATE Here's what's in development.log:

/!\ FAILSAFE /!\  Sat Nov 28 22:11:12 -0500 2009
  Status: 500 Internal Server Error
  no such file to load -- mysql
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require'

FYI I created the application by calling:

rails /home/myuser/www/mynewapp -d mysql
3
  • What's in development.log? It looks like you are getting the production mode error page. I tried exactly what you had and it worked fine for me. Commented Nov 29, 2009 at 3:16
  • @MattMcKnight development.log has now been posted above Commented Nov 29, 2009 at 3:21
  • Which version of Ruby? Rails? Database? MySQL? Which OS? I ask because the latest versions of Rails have SQLite3 baked right in, and the lastest versions of Rails don't use Webrick as the default web server. (They use Mongrel). Commented Jan 8, 2010 at 14:49

5 Answers 5

2

You're not able to load the MySQL database driver. I'm guessing it's not installed. You could try this:

sudo gem install mysql

I'm guessing though that you probably don't have a MySQL database set up. Most people use sqlite3 for development. Your config/database.yml should look like:

development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

If you don't have sqlite3 installed just run

sudo gem install sqlite3-ruby

Then run your migrations and you should be all set

rake db:migrate

Update I posted this here so I could use some formatting.

In the future just call:

rails /path/to/app

This will make Rails use the default database which is sqlite3. You can then change the production database if/when you decided to deploy.

Good luck.

Sign up to request clarification or add additional context in comments.

4 Comments

yup, you pretty much got it totally covered here.
Hey Steve, What OS are you running. Your obviously missing something :) I've seen errors like that on OS X system where I've forgotten to install developer tools. I would run a google search along the lines of <strong>Your operation System</strong> install sqlite3
Oops didn't realize that html tags weren't allowed in comments. Ignore the <strong> tag :)
I'm running Ubuntu. I solved the problem. I needed to call "sudo apt-get install sqlite3 swig libsqlite3-ruby libsqlite3-dev" before I could install that sqlite3-ruby gem. Thanks for the help! I am now up and running with Rails!!! :-)
2

Rails assumes you'll be using a database. If you don't give it a valid connection string in database.yml, it chokes right out of the gate. This is a valid assumption since any real web app will be using a database.

But, if you're just trying to mess around with how the views and controllers work, you can disable the database functionality entirely. To do so, add this to your config/environment.rb:

config.frameworks -= [ :active_record ]

1 Comment

That's a great debugging tip!
1

From the brief error you have posted you might want to check that you have the mysql gem installed if you are planning on using mysql.

If you are on linux try:

gem install mysql

1 Comment

yes! and also just to make sure have it in your PATH Variable in your shell profile as well.. that way you can test it.
0

It's trying to load MySQL driver. Did you edit config/database.yml? Mine looks like this:

# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

Also, switch to Agile Web Development with Rails, Third Edition. It's a good tutorial and still mostly works with the latest version of rails, even though it is written for 2.2.

1 Comment

thanks for the book recommendation! I will see if they've got it on Safari
-1
  1. Check the log in your /log directory. It will give you far better error information.
  2. My guess is that you're getting a double render error--since you're calling render explicitly, you need to put a return statement after your render call. -- By default, the controller tries to render the view that matches your controller after the controller's method completes.

2 Comments

adding return doesn't seem to help. I posted the first few lines of the development.log file. I can post the rest if need be, but I suspect that first error message is the problem. I'm going to look into it...
I tried just what he had and it worked fine. It's not a double render error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.