1

在我的简单 Rails 3 应用程序中,两个模型之间存在 has_one、has_many 关系。我在创建时将“所有者”的 ID 传递给孩子:

动物模型

has_many :claims, :foreign_key => 'animal_id'
has_many :conditions, :foreign_key => 'animal_id'

索赔模型

has_one :animal, :foreign_key => 'PVID'
has_many :payments, :dependent => :destroy

支付模式

belongs_to :claim

我分别使用隐藏表单将 animal_id 和 claim_id 传递给索赔和支付模型。

我想做的是在创建时将用户重定向到父模型。因此,例如:

如果用户正在创建新的索赔,索赔表单将自动插入 animal_id。重定向回动物记录的正确方法是什么?

format.html { redirect_to claim_animal_path, notice: 'Claim was successfully created.' }

任何指针将不胜感激!

4

1 回答 1

3

根据您的路线文件,animal_path助手将接受动物的 id。就像是

format.html { redirect_to animal_path @claim.animal.id, notice: 'Claim was successfully created.' }

可能会工作。

于 2012-11-21T01:35:08.603 回答