我想知道我应该接受什么样的查询才能更新我的数据。我的模型由客户、兴趣和经理组成
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
或者我应该根据兴趣渲染模型视图然后应用更改?