Reputation: 11346
My migration is as follows:
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :email
t.string :password
t.string :name
t.boolean :male
t.boolean :admin
t.timestamps
end
end
def self.down
drop_table :users
end
end
When I go to script/console and type "User", Rails does not recognize the class.
Upvotes: 0
Views: 600
Reputation: 16898
Did you run script/generate model User ...
or script/generate migration CreateUser...
?
If you do not generate the model, it won't be available in the console, as Rails doesn't know it exists.
Rails also does not create a modelname_id
field, it simply creates an id
field which autoincrements.
I hope this helps.
Upvotes: 4
Reputation: 3563
1) The migration will create an auto-incrementing "id" column. (I've never seen a migration create a class_id column unless it was specified).
2) You will need to declare this class in a app/model/user.rb file
class User < ActiveRecord::Base
#class methods go here
end
More importantly I want to recommend the restful_authentication plugin. It's the community standard for user authentication (meaning it's battle tested, regularly updated, and conforms to most use cases).
Upvotes: 3