In my simple Rails 3 application I have a has_one, has_many relationship between two models. I am passing the id of the ‘owner’ to the child upon creation:
Animal Model
has_many :claims, :foreign_key => 'animal_id'
has_many :conditions, :foreign_key => 'animal_id'
Claim Model
has_one :animal, :foreign_key => 'PVID'
has_many :payments, :dependent => :destroy
Payment Model
belongs_to :claim
I am passing the animal_id and claim_id to the claim and payment models respectively using hidden forms.
What I would like to do is redirect the user to the parent model upon creation. So, for example:
If the user was creating a new claim, the claim form would automatically have the animal_id inserted. What is the correct way to redirect back to the animals record?
format.html { redirect_to claim_animal_path, notice: 'Claim was successfully created.' }
Any pointers would be appreciated!
Depending on your routes file, the
animal_pathhelper will accept an id for an animal. Something likewould probably work.