Forum: Ruby on Rails Adding new items with belongs_to/has_many

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
minter (Guest)
on 2005-11-23 18:43
(Received via mailing list)
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:

<select id="link_category" name="link[category]">

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:

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

<*> Your use of Yahoo! Groups is subject to:
This topic is locked and can not be replied to.