Rails 3. Getting multiple things from different tables -


i developing api in ruby on rails 3 , in api got users , users can friends. handled through contacts. when user "asks" or contacts create array takes ids of each user , user object them can real name of contact , not contact id.

this works fine, need id of contact can example delete contacts in iphone app developing. how can this? how can below code modify contact id each user , user object?

http://pastie.org/1847350

update

the current json output pastie.org/1848590. want contact ids sub array of main user object array. latest message now.

thankful input!

contact user, think need create user model , add self association class_name: "contact" , relation b 1 many relationship 1 user has_many contacts.

 has_many :contacts, class: "contacts", foreign_key: "contact_id"       

here cast this

http://railscasts.com/episodes/163-self-referential-association 

after association need find user ,

@users.collect{|user| user.contacts } 

returns list of contacts think might you.

cheers


Comments