Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- model/User.rb
- class User < ActiveRecord::Base
- attr_accessor :password
- attr_accessible :name, :email, :password, :password_confirmation
- has_many :microposts, :dependent => :destroy
- has_many :users_followers, :foreign_key => "follower_id",
- :dependent => :destroy
- has_many :following, :through => :users_followers, :source => :followed
- ...
- end
- model/users_follower.rb
- lass UsersFollower < ActiveRecord::Base
- attr_accessible :followed_id
- belongs_to :follower, :class_name => "User"
- belongs_to :followed, :class_name => "User"
- validates :follower_id, :presence => true
- validates :followed_id, :presence => true
- end
- ERROR
- rails c --sandbox
- Loading development environment in sandbox (Rails 3.0.3)
- Any modifications you make will be rolled back on exit
- ruby-1.9.2-p136 :001 > user = Users.first
- NameError: uninitialized constant Users
- from (irb):1
- from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands/console.rb:44:in `start'
- from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands/console.rb:8:in `start'
- from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands.rb:23:in `<top (required)>'
- from script/rails:6:in `require'
- from script/rails:6:in `<main>'
- ruby-1.9.2-p136 :002 > user = User.first
- => #<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>
- ruby-1.9.2-p136 :003 > user.users_followers.create!(:followed_id => 2)
- => #<UsersFollower follower_id: 1, followed_id: 2>
- ruby-1.9.2-p136 :004 > followed = user.users_followers.find_by_followed_id(2)
- => #<UsersFollower follower_id: 1, followed_id: 2>
- ruby-1.9.2-p136 :005 > followed.destroy
- NoMethodError: undefined method `eq' for nil:NilClass
- 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'
- from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/persistence.rb:79:in `destroy'
- from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/locking/optimistic.rb:110:in `destroy'
- 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'
- 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'
- from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/callbacks.rb:260:in `destroy'
- 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'
- 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'
- 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'
- from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/transactions.rb:204:in `transaction'
- 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'
- from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.3/lib/active_record/transactions.rb:232:in `destroy'
- from (irb):5
- from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands/console.rb:44:in `start'
- from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands/console.rb:8:in `start'
- from /home/dbranco/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/commands.rb:23:in `<top (required)>'
- from script/rails:6:in `require'
- from script/rails:6:in `<main>'ruby-1.9.2-p136 :006 >
- ruby-1.9.2-p136 :007 >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement