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
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
modification. Categories has_many :links, and Links belongs_to

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
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])

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”
the hash with that object? What’s the scoop on how to make those two
classes happy with each other?


------------------------ Yahoo! Groups Sponsor --------------------~–>
AIDS in India: A “lurking bomb.” Click and help stop AIDS now.

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