I am running ruby on rails on Ubuntu 9.10. Every time I run ruby script/console from the terminal for debugging this is what I get I get in return.
Loading development environment (Rails 2.2.3)
/usr/local/lib/site_ruby/1.8/rubygems.rb:223:in `activate':NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map
>>
Ruby On Rails Errorsruby script/console
Page 1 of 1
8 Replies - 2055 Views - Last Post: 25 November 2010 - 08:08 PM
Replies To: Ruby On Rails Errors
#2
Re: Ruby On Rails Errors
Posted 23 November 2010 - 09:26 PM
seems you are calling a method on a nil object, will have to see some code to be able to figure out how to fix this bug
#3
Re: Ruby On Rails Errors
Posted 23 November 2010 - 09:35 PM
I am try to create database for registering user. Here is exactly the steps I take.
d48laws@ubuntu:~$ sudo su
[sudo] password for d48laws:
root@ubuntu:/home/d48laws# cd project
root@ubuntu:/home/d48laws/projecte# ruby script/console
Loading development environment (Rails 2.2.3)
/usr/local/lib/site_ruby/1.8/rubygems.rb:223:in `activate':NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map
>>
d48laws@ubuntu:~$ sudo su
[sudo] password for d48laws:
root@ubuntu:/home/d48laws# cd project
root@ubuntu:/home/d48laws/projecte# ruby script/console
Loading development environment (Rails 2.2.3)
/usr/local/lib/site_ruby/1.8/rubygems.rb:223:in `activate':NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map
>>
#4
Re: Ruby On Rails Errors
Posted 23 November 2010 - 09:39 PM
where's your source code?, I cant know what the problem is without seeing some code.
#5
Re: Ruby On Rails Errors
Posted 23 November 2010 - 09:50 PM
class User < ActiveRecord::Base
# Max & min lengths for all fields
SCREEN_NAME_MIN_LENGTH = 4
SCREEN_NAME_MAX_LENGTH = 20
PASSWORD_MIN_LENGTH = 4
PASSWORD_MIN_LENGTH = 40
EMAIL_MAX_LENGTH = 50
SCREEN_NAME_RANGE = SCREEN_NAME_MIN_LENGTH..SCREEN_NAME_MAX_LENGTH
PASSWORD_RANGE = PASSWORD_MIN_LENGTH..PASSWORD_MAX_LENGTH
code
validates_uniqueness_of :screen_name, :email
validates_lenth_of :screen_name, :within => SCREEN_NAME_RANGE
validates_lenth_of :password, :within => PASSWORD_RANGE
validates_lenth_of :email, :maximum => EMAIL_MAX_LENGTH
validates_format_of :screen_name,
:with => /^[A-Z0-9_]*$/i,
:message => "must contain only letters," +
"numbers, and underscores"
validates_format_of :email,
:with => /^[A-Z0-9._%-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i,
:message => "must be a valid email address"
end
terminal
ruby script/console
Loading development environment (Rails 2.2.3)
/usr/local/lib/site_ruby/1.8/rubygems.rb:223:in `activate':NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map
>> user = User.new(:screen_name => "me",
?> :email => " ",
?> :password => "a")
/home/d48laws/blubird_cafe/app/models/user.rb:7: warning: already initialized constant PASSWORD_MIN_LENGTH
NameError: uninitialized constant User::PASSWORD_MAX_LENGTH
from /home/d48laws/blubird_cafe/vendor/rails/activesupport/lib/active_support/dependencies.rb:102:in `const_missing'
from /home/d48laws/blubird_cafe/app/models/user.rb:10
from /home/d48laws/blubird_cafe/vendor/rails/activesupport/lib/active_support/dependencies.rb:382:in `load_without_new_constant_marking'
from /home/d48laws/blubird_cafe/vendor/rails/activesupport/lib/active_support/dependencies.rb:382:in `load_file'
from /home/d48laws/blubird_cafe/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /home/d48laws/blubird_cafe/vendor/rails/activesupport/lib/active_support/dependencies.rb:381:in `load_file'
from /home/d48laws/blubird_cafe/vendor/rails/activesupport/lib/active_support/dependencies.rb:256:in `require_or_load'
from /home/d48laws/blubird_cafe/vendor/rails/activesupport/lib/active_support/dependencies.rb:427:in `load_missing_constant'
from /home/d48laws/blubird_cafe/vendor/rails/activesupport/lib/active_support/dependencies.rb:77:in `const_missing'
from /home/d48laws/blubird_cafe/vendor/rails/activesupport/lib/active_support/dependencies.rb:89:in `const_missing'
from (irb):4
MOD EDIT: When posting code...USE CODE TAGS!!!
This post has been edited by JackOfAllTrades: 24 November 2010 - 06:22 AM
#6
Re: Ruby On Rails Errors
Posted 23 November 2010 - 09:59 PM
well you have an obvious spelling error.. validates_lenth_of should be validates_length_of
#7
Re: Ruby On Rails Errors
Posted 23 November 2010 - 10:02 PM
you're defining password_min_length twice and not defining password_max_length at all
causes
to give you that error since max length is undefined
causes
PASSWORD_RANGE = PASSWORD_MIN_LENGTH..PASSWORD_MAX_LENGTH
to give you that error since max length is undefined
#8
Re: Ruby On Rails Errors
Posted 24 November 2010 - 06:22 AM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|