0
我想知道应该接受什么样的查询来允许我的数据更新。我的模型是由客户端,利息和经理从其他模型更改数据
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
或者我应该给予利息的模型图,然后向变化?
不知道如何应用它!我已更新我的客户,以表明它如何完成? – Jseb 2012-07-26 18:41:34
正如我所说 - 启动与轨道控制台控制台,并尝试如果步骤正在做你想做的! – bento 2012-07-26 20:12:34