Ruby On Rails Errors

ruby script/console

Page 1 of 1

8 Replies - 2467 Views - Last Post: 25 November 2010 - 08:08 PM Rate Topic: -----

#1 kwikfox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-April 10

Ruby On Rails Errors

Posted 23 November 2010 - 09:04 PM

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
>>
Is This A Good Question/Topic? 0
  • +

Replies To: Ruby On Rails Errors

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

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
Was This Post Helpful? 0
  • +
  • -

#3 kwikfox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-April 10

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
>>
Was This Post Helpful? 0
  • +
  • -

#4 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

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.
Was This Post Helpful? 0
  • +
  • -

#5 kwikfox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-April 10

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!!!

:code:

This post has been edited by JackOfAllTrades: 24 November 2010 - 06:22 AM

Was This Post Helpful? 0
  • +
  • -

#6 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

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
Was This Post Helpful? 1
  • +
  • -

#7 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 444
  • View blog
  • Posts: 1,492
  • Joined: 28-April 09

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

PASSWORD_RANGE = PASSWORD_MIN_LENGTH..PASSWORD_MAX_LENGTH



to give you that error since max length is undefined
Was This Post Helpful? 2
  • +
  • -

#8 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: Ruby On Rails Errors

Posted 24 November 2010 - 06:22 AM

kwikfox, when posting code PLEASE use CODE TAGS, as shown below:

:code:
Was This Post Helpful? 0
  • +
  • -

#9 kwikfox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-April 10

Re: Ruby On Rails Errors

Posted 25 November 2010 - 08:08 PM

Thanks to all.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1