
Untitled
By: a guest on
Aug 9th, 2012 | syntax:
None | size: 1.10 KB | hits: 6 | expires: Never
Changing Data from an other model
Clients his has follow
id
name
email
password
Interest
id
description
manager
customer_id
interest_id
created_at
The relationship his has follow
class Client < ActiveRecord::Base
has_many :music_interest_managers
has_many :music_interests, through => :music_interest_managers
end
class MusicInterest < ActiveRecord::Base
has_many :music_interest_managers
has_many :clients, through => :music_interest_managers
end
class MusicInterestManager < ActiveRecord::Base
belongs_to :music_interests
belongs_to :client
end
@client = Client.find(params[:id])
@manager = @client.manager.build(params[:manager])
@interest = @interest.manager.build(params[:interest])
def update
@client = Client.find(params[:id])
@interest = @client.music_interests.build(params[:interest])
if @client.update_attributes(params[:client])
flash[:success] = "Profile updated"
#sign_in @client
redirect_to @client
else
render 'edit'
end
end
@client = Client.find(params[:id])
@interest = @client.music_interests.build(params[:interest])