Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 4.02 KB | None | 0 0
  1. model/User.rb
  2.  
  3. class User < ActiveRecord::Base
  4.   attr_accessor   :password
  5.   attr_accessible :name, :email, :password, :password_confirmation
  6.  
  7.   has_many :microposts, :dependent => :destroy
  8.   has_many :users_followers, :foreign_key => "follower_id",
  9.                              :dependent => :destroy
  10.   has_many :following, :through => :users_followers, :source => :followed
  11.  
  12. ...
  13. end
  14.  
  15. model/users_follower.rb
  16.  
  17. lass UsersFollower < ActiveRecord::Base
  18.   attr_accessible :followed_id
  19.  
  20.   belongs_to :follower, :class_name => "User"
  21.   belongs_to :followed, :class_name => "User"
  22.  
  23.   validates :follower_id, :presence => true
  24.   validates :followed_id, :presence => true
  25.  
  26. end
  27.  
  28.  
  29.  
  30. ERROR
  31.  
  32. rails c --sandbox
  33. Loading development environment in sandbox (Rails 3.0.3)
  34. Any modifications you make will be rolled back on exit
  35. ruby-1.9.2-p136 :001 > user = Users.first
  36. NameError: uninitialized constant Users
  37.     from (irb):1
  38.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands/console.rb:44:in `start'
  39.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands/console.rb:8:in `start'
  40.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands.rb:23:in `<top (required)>'
  41.     from script/rails:6:in `require'
  42.     from script/rails:6:in `<main>'
  43. ruby-1.9.2-p136 :002 > user = User.first
  44. => #<User id: 1, name: "Example User", email: "example@railstutorial.org", created_at: "2011-02-18 23:33:01", updated_at: "2011-02-18 23:33:01", encrypted_password: "3a4b628f8d336b53a22c46b35b4e1d341b0d5827c96357f55ed...", salt: "898819f932e3973b8bf4b6acbf3434791fd7d45b5c73dbb8ef7...", admin: true>
  45. ruby-1.9.2-p136 :003 > user.users_followers.create!(:followed_id => 2)
  46. => #<UsersFollower follower_id: 1, followed_id: 2>
  47. ruby-1.9.2-p136 :004 > followed = user.users_followers.find_by_followed_id(2)
  48. => #<UsersFollower follower_id: 1, followed_id: 2>
  49. ruby-1.9.2-p136 :005 > followed.destroy
  50. NoMethodError: undefined method `eq' for nil:NilClass
  51.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/whiny_nil.rb:48:in `method_missing'
  52.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/persistence.rb:79:in `destroy'
  53.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/locking/optimistic.rb:110:in `destroy'
  54.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/callbacks.rb:260:in `block in destroy'
  55.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:413:in `_run_destroy_callbacks'
  56.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/callbacks.rb:260:in `destroy'
  57.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/transactions.rb:232:in `block in destroy'
  58.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/transactions.rb:289:in `block in with_transaction_returning_status'
  59.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
  60.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/transactions.rb:204:in `transaction'
  61.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/transactions.rb:287:in `with_transaction_returning_status'
  62.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/transactions.rb:232:in `destroy'
  63.     from (irb):5
  64.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands/console.rb:44:in `start'
  65.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands/console.rb:8:in `start'
  66.     from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands.rb:23:in `<top (required)>'
  67.     from script/rails:6:in `require'
  68.     from script/rails:6:in `<main>'ruby-1.9.2-p136 :006 >
  69. ruby-1.9.2-p136 :007 >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement