Ruby 关于两个表单之间字段调用问题,求指点

lengcb · 2015年10月21日 · 最后由 lengcb 回复于 2015年10月21日 · 1307 次阅读

这里有两个表单,一个父表(teams),一个子表(users)(新手,名称说法上有问题请指出),team.rb 中 has_many :users, user.rb 中 belongs_to :team 我知道 team 中调用 user 表中的字段,用 accepts_nested_attributes_for :users。单反过来,user 中调用 team 的字段就不会了,请各位高手指点

accepts_nested_attributes_for :team, 在创建 user 的表单里面,f.fields_for :team, @user.team || Team.new do |f1|, 试试看行不行

#1 楼 @leomayleomay ok,可以,解决了

需要 登录 后方可回复, 如果你还没有账号请 注册新账号