views:

46

answers:

1

Hello, I'm using Rails 3 with devise.

I have a table books which has a column for user_id, which is related to the Users table (user.rb)

I'm trying to create a Scope that shows all the books with the user's email address (Books joined to Users)

class Note < ActiveRecord::Base
 scope :personal, proc {|user| where(:user_id => user.id) }
end

Can you help me understand why this is erroring with: "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id"

thanks

+1  A: 

You need define a belongs_to assocation.

class Note < ActiveRecord::Base
 belongs_to :personal, :class_name => 'User', :foreign_key => 'user_id'
end
shingara
Define it and then use the scope? Can you show me the end to end? From model > controller > view. thxs
AnApprentice