# Adding new items with belongs\_to/has\_many

**URL:** <https://www.ruby-forum.com/t/adding-new-items-with-belongs-to-has-many/48709>\
**Category:** Rails\
**Created:** [November 23, 2005, 5:43pm UTC](https://www.ruby-forum.com/t/adding-new-items-with-belongs-to-has-many/48709 "2005-11-23T17:43:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![minter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/278dde/32.png) [@minter](https://www.ruby-forum.com/u/minter)\
**Post date:** [November 23, 2005, 5:43pm UTC](https://www.ruby-forum.com/t/adding-new-items-with-belongs-to-has-many/48709/1 "2005-11-23T17:43:07Z")

</div>

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](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](http://groups.yahoo.com/group/pragstudiorails-alumni/)

\<\*\> To unsubscribe from this group, send an email to:  
removed\_email\_address@domain.invalid

\<\*\> Your use of Yahoo! Groups is subject to:  
[Yahoo | Mail, Weather, Search, Politics, News, Finance, Sports & Videos](http://docs.yahoo.com/info/terms/)
