When trying to establish relationship between 2 models, we have to specify :class_name if 'module' is different
/app/models/abc/address.rb
module ABC
class Address < ActiveRecord::Base
belongs_to :user
attr_accessible :user_id, :address1, :address2, :city, :country, :state, :zip, :is_primary_address
end
end
/app/models/user.rb
class User < ActiveRecord::Base
has_many :addresses, :class_name => ABC::Address
...
...
end
/app/models/abc/address.rb
module ABC
class Address < ActiveRecord::Base
belongs_to :user
attr_accessible :user_id, :address1, :address2, :city, :country, :state, :zip, :is_primary_address
end
end
/app/models/user.rb
class User < ActiveRecord::Base
has_many :addresses, :class_name => ABC::Address
...
...
end
Thanks Sai for the post which helps me a lot..
ReplyDelete