Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 9th, 2012  |  syntax: None  |  size: 1.10 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Changing Data from an other model
  2. Clients his has follow
  3. id
  4. name
  5. email
  6. password
  7.  
  8. Interest
  9. id
  10. description
  11.  
  12. manager
  13. customer_id
  14. interest_id
  15. created_at
  16.        
  17. The relationship his has follow
  18. class Client < ActiveRecord::Base
  19.   has_many :music_interest_managers
  20.   has_many :music_interests, through => :music_interest_managers
  21. end
  22. class MusicInterest < ActiveRecord::Base
  23.   has_many :music_interest_managers
  24.   has_many :clients, through => :music_interest_managers
  25. end
  26. class MusicInterestManager < ActiveRecord::Base
  27.   belongs_to :music_interests
  28.   belongs_to :client
  29. end
  30.        
  31. @client = Client.find(params[:id])
  32. @manager = @client.manager.build(params[:manager])
  33. @interest = @interest.manager.build(params[:interest])
  34.        
  35. def update
  36.     @client = Client.find(params[:id])
  37.     @interest = @client.music_interests.build(params[:interest])
  38.  
  39.     if @client.update_attributes(params[:client])
  40.         flash[:success] = "Profile updated"
  41.         #sign_in @client
  42.         redirect_to @client
  43.     else
  44.         render 'edit'
  45.     end
  46. end
  47.        
  48. @client = Client.find(params[:id])
  49. @interest = @client.music_interests.build(params[:interest])