I'm new to rails and was playing with a simple model with
acts_as_threaded. The sql is...
CREATE TABLE bobbits
(
id integer NOT NULL DEFAULT
nextval('destination_countrycode_id_seq'::regclass),
name character varying(100) NOT NULL,
description text,
parent_id integer,
CONSTRAINT bobbits_pkey PRIMARY KEY (id)
)
and the only change i made after generating scaffolding was of course:
class Bobbit < ActiveRecord::Base
acts_as_tree :order => "name"
end
Now I expected that rendering of a bobbit in the browser would present
an drop-down list for parent, but no such luck. Whats up?
No. acts_as_tree is an extension to ActiveRecord -- the objects-
wrapping-db mechanism in rails (Model). Dropdowns are a function of
the view. By default, the scaffold will generate a text_column for
almost everything but date, datetime, and boolean fields.
If you want a dropdown for parent, you need to change the scaffolded
field that probably looks like:
<p>
<b>Parent</b>
<%= text_field f.parent_id %> <----- this one
</p>
The select object accepts the name of the attribute to be filled
(parent_id), and an enumerable set of options. In the example above,
you're retrieving all the Bobbits, ordered by their name, and creating
an array of name/val pairs to be displayed in the dropdown.