s. shartles wrote: > In the User model: > has_many :properties > > In the Property model: > belongs_to :user, :class_name => "User", :foreign_key => > 'updated_by' > > > Here's what I see inside of the rails console: >>> prop = Property.first > => #<Property id: 1, name: "Main Street Center", ..., updated_by: nil> >>> usr = User.first > => #<User id: 1, login: "sshartles", name: "Sam Shartles", ... > >>> prop.user = usr > => #<User id: 1, login: "sshartles", name: "Sam Shartles", ... > >>> prop.updated_by > => 1 >>> prop.updated_by.name > NoMethodError: undefined method `name' for 1:Fixnum > from (irb):5 >>>
Yeah the fixnum error is because updated_by is just an integer field to rails. If you tried: prop.user = usr prop.user.name #=> "Sam Shartles" This should get you are trying to acheive: In the User model: has_many :properties, :foreign_key => 'updated_by' In the Property model: belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by' I must admit in the past I've tended to use 'updated_by_id' instead as your field name that way you can access both updated_by_id (returns int) and updated_by (returns user). You may also look at the userstamp plugin: http://github.com/delynn/userstamp/tree/master Cheers Luke -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---