Reputation: 6880
i am using Rails 3.2.3 on Ubuntu and below is my schema file and model file code:
schema.rb
ActiveRecord::Schema.define(:version => 20120528062318) do
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "password_digest"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
end
user.rb
class User < ActiveRecord::Base
attr_accessible :email, :name, :password, :password_confirmation
has_secure_password
before_save { |user| user.email = email.downcase }
valides :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
uniqueness: true
validates :password, presence: true, length: { minimum: 6 }
validates :password_confirmation, presence: true
end
i tried to enter a new record to the database from the rails console with the command: User.create(name: 'Hilal Agil', email: '[email protected]', password: 'welcome', password_confirmation: 'welcome') and i am getting the error below:
NoMethodError: undefined method `valides' for #<Class:0xaeba6cc>
from /home/hilarl/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.3/lib/active_record/dynamic_matchers.rb:50:in `method_missing'
from /home/hilarl/workspace/twitster/app/models/user.rb:17:in `<class:User>'
from /home/hilarl/workspace/twitster/app/models/user.rb:12:in `<top (required)>'
from /home/hilarl/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:469:in `load'
from /home/hilarl/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:469:in `block in load_file'
from /home/hilarl/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:639:in `new_constants_in'
from /home/hilarl/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:468:in `load_file'
from /home/hilarl/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:353:in `require_or_load'
from /home/hilarl/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:502:in `load_missing_consta
nt'
from /home/hilarl/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:192:in `block in const_miss
ing'
from /home/hilarl/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in `each'
from /home/hilarl/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in `const_missing'
from (irb):2
from /home/hilarl/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in `start'
from /home/hilarl/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in `start'
from /home/hilarl/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'1.9.3p194 :003 >
Any idea what i am doing wrong here? thanks.
Upvotes: 0
Views: 168
Reputation: 14694
You have a typo. This line:
valides :name, presence: true, length: { maximum: 50 }
Should say this:
validates :name, presence: true, length: { maximum: 50 }
If you look at the error message you can see that it is telling you that you are trying to call a method name valides, which does not exist.
Upvotes: 5