Script/generate scaffold user

NameError in UsersController#index

uninitialized constant UsersController::User

RAILS_ROOT: C:/RailsApps/rgams
Application Trace | Framework Trace | Full Trace

c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:492:in
const_missing' app/controllers/users_controller.rb:5:inindex’

c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:492:in
const_missing' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:insend’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in
perform_action_without_filters' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:580:incall_filters’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:573:in
perform_action_without_benchmark' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:inperform_action_without_rescue’
c:/ruby/lib/ruby/1.8/benchmark.rb:293:in measure' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:inperform_action_without_rescue’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/rescue.rb:201:in
perform_action_without_caching' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:13:inperform_action’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in
cache' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/query_cache.rb:8:incache’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:12:in
perform_action' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:insend’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in
process_without_filters' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:569:inprocess_without_session_management_support’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/session_management.rb:130:in
process' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:389:inprocess’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:149:in
handle_request' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:107:indispatch’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in
synchronize' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:indispatch’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:120:in
dispatch_cgi' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:35:indispatch’
c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:112:in
handle_dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:78:inservice’
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:inrun’
c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:instart’
c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:95:instart’
c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in each' c:/ruby/lib/ruby/1.8/webrick/server.rb:92:instart’
c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:82:instart’
c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:62:in
dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/servers/webrick.rb:66 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:ingem_original_require’
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:inrequire’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in
new_constants_in' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:inrequire’
c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/server.rb:39
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire’
script/server:3

c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:492:in
const_missing' app/controllers/users_controller.rb:5:inindex’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in
send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:inperform_action_without_filters’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:580:in
call_filters' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:573:inperform_action_without_benchmark’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue' c:/ruby/lib/ruby/1.8/benchmark.rb:293:inmeasure’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/rescue.rb:201:inperform_action_without_caching’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:13:in
perform_action' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:33:incache’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/query_cache.rb:8:in
cache' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:12:inperform_action’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in
send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:inprocess_without_filters’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:569:in
process_without_session_management_support' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/session_management.rb:130:inprocess’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:389:in
process' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:149:inhandle_request’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:107:in
dispatch' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:insynchronize’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in
dispatch' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:120:indispatch_cgi’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:35:in
dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:112:inhandle_dispatch’
c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:78:in
service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:inservice’
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in run' c:/ruby/lib/ruby/1.8/webrick/server.rb:173:instart_thread’
c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:instart_thread’
c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:92:ineach’
c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:23:instart’
c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in start' c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:62:indispatch’
c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/servers/webrick.rb:66
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in
require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:innew_constants_in’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in
require' c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/server.rb:39 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:ingem_original_require’
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require’
script/server:3

Request

Parameters:

None

Show session dump


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

Response

Headers:

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

What’s wrong??

Thanks.

could you put the ocntroller code plz?

Where is that located?

Thanks

On Jul 9, 2008, at 12:13 PM, Wolas! wrote:

could you put the ocntroller code plz?

On Jul 9, 5:02 pm, Justin To [email protected] wrote:

NameError in UsersController#index

uninitialized constant UsersController::User

…Or just see if you even have a User class somewhere.
Do you perhaps not have app/models/user.rb?

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Mmm… I’m trying to follow
http://media.rubyonrails.org/video/rails_take2_with_sound.mov, the rails
video, and I created my model called User,

in the HomeController#index file I have

scaffold :User

And I get this error when I reload the page:

NoMethodError in HomeController#index

undefined method `scaffold’ for HomeController:Class

Thanks for the help

On Jul 9, 2008, at 12:44 PM, Justin To wrote:

NoMethodError in HomeController#index

undefined method `scaffold’ for HomeController:Class

Thanks for the help

You need to either use an old version of Rails (say, 1.2.6) for that
tutorial or find a tutorial that is based on Rails 2.x

The dynamic scaffold as used in that old tutorial is no longer
available. You can use the new static scaffold generator to get
started:

script/generate scaffold

Read the help message that it provides, and then give it the arguments
that you need (and perhaps you can still follow most of the old
tutorial).

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Whenever I use script/generate scaffold, I get this error

for script/generate scaffold Requirement:

[http://localhost:3000/requirement]
Routing Error

No route matches “/requirement” with {:method=>:get}

Thanks for the help.

I have a database rgams_dev with table users

users:
user_email_id | varchar(100)
user_password | varchar(100)

I typed:

C:\RailsApps\rgams\script\generate scaffold User [user_email_id:varchar,
user_password:varchar]

There’s no problem creating the corresponding files and what not, but I
still get the error:

Routing Error

No route matches “/user” with {:method=>:get}


This is my database.yml

MySQL 5.0.x for Win32

development:
adapter: mysql
encoding: utf8
database: rgams_dev
username: root
password: symantec
host: localhost
test:
adapter: mysql
database: rgams_test
username: root
password: symantec
host: localhost
production:
adapter: mysql
database: rgams_prod
username: root
password: symantec
host: localhost

Do I need to include ‘socket:’ into that? Like,

development:
adapter: mysql
encoding: utf8
database: rgams_dev
username: root
password: symantec
host: localhost
socket:

If so, I haven’t been able to find the mysql.sock file. Or if it’s not
that one that’s suppose to go there, what is?

Thanks so much!

You’re doin it wrong.

C:\RailsApps\rgams\script> generate scaffold User [user_email_id:varchar,
user_password:varchar]

Rails has its own way of defining tables. Most of the tutorials out
there
are terriblly out of date.
You’re trying to use sql stuff when creating your tablle, That’s causing
the
generators to freak out and not build what you need.

You want to do this:

c:
cd\RailsApps\rgams
ruby script\generate scaffold user email:string password:string

This generates a migration to build the table. The primary key , though
not
specified, will be created for you and it will be called “id”. In the
example you provided, your field names were prefixed with user_ which is
not
necessary (or good practice) in Rails. Finally, I assume you want to
store
their email address, not email_id… Rails, by default, thinks _id
means
a key to another table (a foreign key, but there’s not Foreign Key
Constraint.

Really, you should just buy

PDF and learn how this all actually works. It can be very frustrating
learning Rails off the web.

On Wed, Jul 9, 2008 at 12:47 PM, Justin To
[email protected]

On Jul 9, 2008, at 1:27 PM, Justin To wrote:

Whenever I use script/generate scaffold, I get this error

for script/generate scaffold Requirement:

[http://localhost:3000/requirement]
Routing Error

No route matches “/requirement” with {:method=>:get}

Thanks for the help.

When I run that (against a Rails 2.0.2 project):

$ script/generate scaffold
Usage: script/generate scaffold ModelName [field:type, field:type]

Options:
–skip-timestamps Don’t add timestamps to the
migration file for this model
–skip-migration Don’t generate a migration file
for this model

Rails Info:
-v, --version Show the Rails version number
and quit.
-h, --help Show this help message and quit.

General Options:
-p, --pretend Run but do not make any changes.
-f, --force Overwrite files that already
exist.
-s, --skip Skip files that already exist.
-q, --quiet Suppress normal output.
-t, --backtrace Debugging: show backtrace on
errors.
-c, --svn Modify files with subversion.
(Note: svn must be in path)

Description:
Scaffolds an entire resource, from model and migration to
controller and
views, along with a full test suite. The resource is ready to use
as a
starting point for your restful, resource-oriented application.

 Pass the name of the model, either CamelCased or under_scored, as

the first
argument, and an optional list of attribute pairs.

 Attribute pairs are column_name:sql_type arguments specifying the
 model's attributes. Timestamps are added by default, so you don't

have to
specify them by hand as ‘created_at:datetime updated_at:datetime’.

 You don't have to think up every attribute up front, but it helps

to
sketch out a few so you can start working with the resource
immediately.

 For example, `scaffold post title:string body:text

published:boolean`
gives you a model with those three attributes, a controller that
handles
the create/show/update/destroy, forms to create and edit your
posts, and
an index that lists them all, as well as a map.resources :posts
declaration in config/routes.rb.

Examples:
./script/generate scaffold post # no attributes, view will be
anemic
./script/generate scaffold post title:string body:text published:boolean
./script/generate scaffold purchase order_id:integer amount:decimal
------------------->8------->8------->8------->8------->8-------

8------->8—

So you need to run the script/generate with the arguments that you
want (and probably restart your server so the new routes can be
parsed) and then continue with the tutorial.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

I would’ve thought by now that that tutorial would’ve been replaced to
stop stuff like this from happening.

Thanks Brian, I am going to purchase the pdf… I managed to figure a
few things out, but when I go to create a new user at

http://localhost:3000/users

this error pops up when i click create:

ActiveRecord::StatementInvalid in UsersController#show

Mysql::Error: Unknown column ‘users.id’ in ‘where clause’: SELECT * FROM
users WHERE (users.id = ‘0’)

This is in users_controller.rb:

def show
@user = User.find(params[:id])

respond_to do |format|
  format.html # show.html.erb
  format.xml  { render :xml => @user }
end

end

In the mysql database, I see the added user, so it added fine.

Thanks