My first attempt at working with a new has_many relationship is
throwing an error in the view when I try to create a new ‘rcost’
instance linked to a ‘resource’ (each resource can have multiple
costs):
I’d really appreciate it if someone could tell me what is going wrong
and how I can create a new rcost instance associated with an existing
resource instance.
rcosts_path is being invoked by form_for, when it computes where the
form should be posting too. Since you’ve got a nested resource you’ve
got to tell form_for which Resource this @rcost belongs to.
Thanks, Fred - very helpful orientation. I assumed (mistakenly,
obviously) that form_for would see the foreign key in @rcost and
therefore know the @resource instance it should be associated with.
I searched around and found two recommendations that appear to address
this issue I am having:
<% form_for([@resource, @rcost]) do |f| %>
and
<% form_for([:resource, @rcost]) do |f| %>
Not sure how behavior will differ with each version, but I will try
them and report back on my results.