I have a simple object, Article, which has_one :parent of the same time.
On my Show page for a given article there will be a “new child” button
which will pass the current :id (or the current Article itself) to the
new form. What is the proper way to hide a reference to this parent in
the form so that when it is submitted back, the create method knows what
to do with it?
I’m confused by where Rails is going to make assumptions for me. Does
article have a property called parent, or parent_id? When I set it do I
just pass in an id and Rails knows what to do with it, or do I have to
create the object myself and then set it? I tried something like this:
<%= hidden_field ‘article’, ‘parent’, @parent %>
where @parent had been defined in the new method as
@parent = Article.find(params[:id])
but I got undefined method `stringify_keys’ for #Article:0x2544068
I’m guessing that’s because I’m trying to pass the object through the
form rather than an id reference to it? But if I pass around just the
id, I can’t really use the above hidden_field reference to set
article.parent, can I?