Beginner problem

Hey all you RoR experts/fanatics!

Let me start by saying: If this is the wrong forum to post in, I humbly
apologize.

I am not normally a forum junkie or anything, but after spending 4 days
reading half a dozen different tutorials on Ruby on Rails and trying to
get a really tiny little application up and running, I have run into a
brick wall that I cannot get past and I am getting desperate for help.

The current tutorial I am working with is:
http://www-128.ibm.com/developerworks/library/l-rubyrails/index.html

(Please let me re-emphasize here that I have read 5-6 different
tutorials now. Please–for the love of God–do not refer me to another
tutorial. They aren’t working for me)

From top to bottom, here is what I have done:

(1) I am using my Macbook running Leopard. It has ruby pre-installed and
I have run the update rails gem. I also am using PostgreSQL (rather than
the MySQL that all of the tutorials use because I am more familiar with
PostgreSQL)

(2) I created a database called “railstest01” in ~/db
export PGDATA=~/db/railstest01
initdb
createdb railstest01
psql railstest01

(then, inside psql, I just created a little test table...)
CREATE TABLE Friends (
    id SERIAL NOT NULL,
    name TEXT NOT NULL,
    PRIMARY KEY (id)
);

INSERT INTO Friends (name) VALUES ('Tiffie');
INSERT INTO Friends (name) VALUES ('Stephen');
INSERT INTO Friends (name) VALUES ('Mike');
...

(2) rails railstest01

(3) I changed ~/railstest01/config/database.yml to be

development:
adapter: postgresql
database: railstest01
host: localhost
username: postgres
password: 12345
timeout: 5000

(Note: On the Macbook, I have to create a user called “postgres” in
order to use PostgreSQL–at least, that’s what I read…)

(4) ruby script/generate model friend

(5) ruby script/generate controller friend

(6) I changed ~/railstest01/app/controllers/friend_controller.rb to be

class FriendController < ApplicationController
model :friend
scaffold :friend
end

(7) ruby script/server

(8) I then browsed to: http://localhost:3000/ and successfully saw the
“Welcome Aboard! You’re riding Ruby on Rails!” splash screen.

(9) Lastly, I browsed to http://localhost:3000/friend/ and was hoping to
see the screen that all the various tutorials told me I would see that
lets me edit the tiny little database.

However… I have yet to be able to do that. I keep getting the same
error (both on my Macbook and on the domain I registered so that I could
play around with Ruby on Rails more publicly). Below is the entire error
I am getting.

If someone could please help me clear up this issue, I would be
extremely grateful. I am on break from the University and was hoping to
mess around with RoR and become a devoted junkie, but I am thus far
unable to even get my “foot in the door.”


THE ERROR

NoMethodError in FriendController#index

undefined method `model’ for FriendController:Class

RAILS_ROOT: /Users/postgres/ruby/railstest01
Application Trace | Framework Trace | Full Trace

app/controllers/friend_controller.rb:2
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in
load_without_new_constant_marking' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:inload_file’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in
new_constants_in' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:202:inload_file’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:94:in
require_or_load' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:248:inload_missing_constant’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:453:in
const_missing' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:465:inconst_missing’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/inflector.rb:257:in
constantize' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/core_ext/string/inflections.rb:148:inconstantize’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/routing.rb:1426:in
recognize' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:inload’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in
load' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:innew_constants_in’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in
load' /Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64 /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:inrequire’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in
new_constants_in' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:inrequire’
/Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39

/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:170:in
handle_request' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:indispatch’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in
dispatch_cgi' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:indispatch’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in
process' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:insynchronize’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in
process' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:inprocess_client’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in
each' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:inprocess_client’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in
run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:ininitialize’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in
new' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:inrun’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in
initialize' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:innew’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in
run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:inrun’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in
each' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:inrun’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in
run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:inrun’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:inrequire’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:inrequire’
script/server:3

app/controllers/friend_controller.rb:2
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in
load_without_new_constant_marking' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:inload_file’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in
new_constants_in' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:202:inload_file’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:94:in
require_or_load' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:248:inload_missing_constant’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:453:in
const_missing' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:465:inconst_missing’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/inflector.rb:257:in
constantize' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/core_ext/string/inflections.rb:148:inconstantize’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/routing.rb:1426:in
recognize' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:170:inhandle_request’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in
dispatch' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:indispatch_cgi’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in
dispatch' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:inprocess’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in
synchronize' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:inprocess’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in
process_client' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:ineach’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in
process_client' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:inrun’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in
initialize' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:innew’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in
run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:ininitialize’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in
new' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:inrun’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in
run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:ineach’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in
run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:inrun’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in
run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243 /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:inload’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in
load' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:innew_constants_in’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in
load' /Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:ingem_original_require’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in
require' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:inrequire’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in
new_constants_in' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:inrequire’
/Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:inrequire’
script/server:3

Request

Parameters:

None

Show session dump


flash: !map:ActionController::Flash::FlashHash {}

Response

Headers:

{“cookie”=>[],
“Cache-Control”=>“no-cache”}

On Dec 22, 2007, at 3:52 PM, Sean F. wrote:

(Note: On the Macbook, I have to create a user called “postgres” in
order to use PostgreSQL–at least, that’s what I read…)

Actually, it is recommended that you create the postgres user to
run postgresql as. You can create all the users you want in psql with

create user new_user with password ‘my_password’;

Then you have to add a line in the pg_hba.conf file. I always create
a separate user for each application.

(6) I changed ~/railstest01/app/controllers/friend_controller.rb to be

class FriendController < ApplicationController
model :friend
scaffold :friend
end

Take out “model :friend” and see what happens.

Peace,
Phillip

Hello.

Unfortunately, I think the tutorial that you are working with is a bit
out of date. I think you’ll probably run into trouble with most of
the Rails tutorials out there right now if you’re using Rails 2.0.x
because scaffold has been deprecated. If you Google for ‘rails
scaffold deprecated’ or something similar you should be able to find
some more information about it.

Katie

On Dec 22, 3:52 pm, Sean F. [email protected]

Basically, with the new scaffold you should do something like this:

ruby script/generate scaffold Friend name:string

This will create the Model, the Controller and the Migration that will
create the columns you specified (in this case, name).

Then you just need to run rake db:migrate and thats it. Remember to
delete the table you have created before running the Migration. You
should always edit the Database trough Migrations.

The problem is that the new scaffold is now RESTful, and I bet the
tutorials you are looking at are not based on RESTful specs. Maybe you
should install Rails 1.2.6 and specify this version on environment.rb
so that you can play with the old scaffold…

Felipe

I forgot to add… I think you might be able to find some more
information about the Rails 2/scaffold thing on this forum too.

[email protected] wrote:

Basically, with the new scaffold you should do something like this:

ruby script/generate scaffold Friend name:string

This will create the Model, the Controller and the Migration that will
create the columns you specified (in this case, name).

Then you just need to run rake db:migrate and thats it. Remember to
delete the table you have created before running the Migration. You
should always edit the Database trough Migrations.

The problem is that the new scaffold is now RESTful, and I bet the
tutorials you are looking at are not based on RESTful specs. Maybe you
should install Rails 1.2.6 and specify this version on environment.rb
so that you can play with the old scaffold…

Felipe

hmm… alright then. Despite what I said previously, can someone suggest
a step-by-step (I’m not a web programmer and I don’t know much about
frameworks) RoR 2.0+ tutorial or guide that I can read to get on my
feet? I don’t know anything about migrations (or even scaffolds for that
matter, since the tutorials I read just said, “do this, now this, and
this. yay it works!”.

Thank you all for your time, too; I appreciate it.

–Sean

I think it is too soon since 2.0 was released. If there is any
tutorial out there covering 2.0, I doubt it is going to be very
complete and aimed at beginners.

I would recommend AWDWR, 2nd edition. It covers Rails 1.2.6, but still
it is very complete. It tells you exactly what you are doing and why.
It has a very good tutorial and after that it covers Rails as a whole.

I started working with it in october. By now I am working on my own
app, reading the part of the book that is not related to the depot app
(the app you develop on the book as a tutorial) and doing coding in my
free time. I actually never finished the depot app (not that the guide
is useless or flawed or anything, it was mostly because of how I learn
things).

I’ve started converting my app to 2.0 in baby steps. Everything new I
create is RESTful, but I’m not in a hurry to refactor the “old” code.
I think it is easier to “learn” 2.0 if you know 1.2, but thats my
opinion.

I would advise you to go trough and create the depot app (from the
AWDWR book) using 1.2.6. After you are done, you will be more prepared
to start creating your own app using 2.0.

AWDWR:
http://www.amazon.com/Agile-Web-Development-Rails-2nd/dp/0977616630/ref=sr_1_1?ie=UTF8&s=books&qid=1198382546&sr=1-1

On Dec 22, 7:11 pm, Sean F. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs