Rails Dispatch

Rails news delivered fresh

Presented by Engine Yard

View Question

Vote on questions you’d like to see answered by the expert contributors

Signup to ask questions or vote for the questions you’d like to see answered.

Hi im quite beginner in rails. i have a problem suggestion will be appreciated.
i have two model “user” and “asset”
an “asset” is created by a “user” and asset" can be assigned to a “user” schema is
Asset { id,name,creator_id,assigned_to_id,price,…}
User{ id,name,….}
now in Asset model class association are
class Asset < ActiveRecord::Base
belongs_to :creator ,:class_name=>’User’
belongs_to :assigned_to, :class_name=>’User’ ,:foreign_key=>’assigned_to_id’

and User Model is

class User < ActiveRecord::Base
//any validation and other stuff
has_many :assets #did not specify either this accosiation #is for creator , or assigned to how can is specify this??

now in Asset show view i can obtain creator name with

but can’t assigned_to name
@asset.assigned_to.name =>(error is )undefined method `first_name’ for nil:NilClas

@asset.assigned_to_id.name=>(error is) undefined method `first_name’ for 1:Fixnum

any suggestion how can i make double association with same model



Asked March 24, 2011