Adding new items with belongs_to/has_many

Originally posted this to the pragmatic studio list. No response there,
so I’m giving it a shot here.

I’m working on my first post-class Rails app - a rewritten replacement
for
a link-collection site. Right now, it’s a very basic setup with a
Categories table (acts_as_tree), and a Links table. Table and foreign
keys appear to be set up fine. I generated a scaffold and did some
minor
modification. Categories has_many :links, and Links belongs_to
:category.

I’ve got a helper function that generates a select() statement like
select(:link, :category). That creates HTML that looks like:

And the option value is the numeric category id number.

When I submit the form, I get an ActiveRecord error that reads:

Category expected, got String

In the request parameters, I see I’m getting “category” => “8”. I
assume
it’s expecting a Category object instead of just the string “8”. In my
scaffold-built controller, the create method is doing the stock:

@link = Link.new(params[:link])
@link.save

Does the scaffold not handle this type of interaction by default? Do I
need to change that to do something like a @category =
Category.find(params[:category]), and replace the value for “category”
in
the hash with that object? What’s the scoop on how to make those two
classes happy with each other?

–Wade

------------------------ Yahoo! Groups Sponsor --------------------~–>
AIDS in India: A “lurking bomb.” Click and help stop AIDS now.
http://us.click.yahoo.com/VpTY2A/lzNLAA/yQLSAA/nhFolB/TM
--------------------------------------------------------------------~->

Yahoo! Groups Links

<*> To visit your group on the web, go to:
Yahoo | Mail, Weather, Search, Politics, News, Finance, Sports & Videos

<*> To unsubscribe from this group, send an email to:
[email protected]

<*> Your use of Yahoo! Groups is subject to:
Yahoo | Mail, Weather, Search, Politics, News, Finance, Sports & Videos