I’m at the stage in learning Rails (and Ruby) where everything seems
disorienting and awkward.
My first self-assigned project is a links manager. I have a Topic model
and a Link model. Topic is defined as acts_as_tree, while Link is
acts_as_list. I have three tables in a database that I think make sense
- one is a join table which I will use for links. But I haven’t even
gotten to that point yet.
A topic can be a parent to other topics or to links, so there are a
number of parent/child relationships going on. I figured the way to
assign a parent to a new topic or a new link would be with check boxes.
Dealing first with topics, when one creates a new Topic one would be
presented with a bunch of checkboxes, one for each existing topic.
Checking a checkbox assigns that topic as the parent to the newly
created topic. (Haven’t even gotten to links yet, but same idea).
There is a “parent_id” column in the topics table. I want to populate
that with the topic id of the checked checkbox.
I have been scratching my head trying to figure out how to write the
check_box form helper in the “create” and “modify” _form partials, and
how to extract the value in the TopicAdmin controller.
In the Topic _form.rhtml partial I have:
<% for topic in @topics %>
(I have defined @topics in the controller as Topic.find_all. I’ve got
zero as the value for nothing checked, as some topics will be top level
with no parents.)
Now I don’t know if that’s the right syntax for the check_box helper,
and if it is I can’t figure out how the controller extracts the value
and puts it into the parent_id attribute of the topics table.
The check boxes show up. They appear to carry their id correctly. I’m
just not succeeding in getting those values inserted into the database
table.
Thank you in advance for any suggestions.