ActiveScaffold dropdown column value from other table

Aplogies for posting a question which I think must be trivial but I
can not find the answer anywhere!

I have posted this to the ActiveScaffold forum but there seems to be
very little activity there, hopefully there is someone here willing to
help ?

I have two tables, Item and Category. Item belongs_to Category which
has_many Items. I am trying to code up an Item form where one of the
fields allows selection of a category.

My ItemController looks like this:

class ItemController < ApplicationController
active_scaffold :item do |config|
columns[:category].ui_type = :select
end
end

which makes the “category” field appear as a drop-down list.

My ItemHelper looks like this:

module ItemHelper
def category_column(record)
if record.category.nil?
“”
else
record.category.summary
end
end

def category_form_column(record,input_name)
options = Category.find(:all).collect do |c|
[ c.summary, c.id ]
end
select :record, :category, options, {:include_blank =>
false, :prefix => input_name}
end
end

The category_form_column helper makes the correct category names
appear in the drop down.

The form is correctly rendered but when I commit, the record shows a
nil category_id and a nil @category.

What am I missing ? I’ve looked everywhere for an example but can’t
find one. I think an ActiveScaffold tutorial on this would be useful.

Thanks for any help…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs