# Has\_many questions

**URL:** <https://www.ruby-forum.com/t/has-many-questions/125632>\
**Category:** Rails\
**Created:** [January 10, 2008, 8:03pm UTC](https://www.ruby-forum.com/t/has-many-questions/125632 "2008-01-10T20:03:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jvazquez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/858c86/32.png) [@jvazquez](https://www.ruby-forum.com/u/jvazquez)\
**Post date:** [January 10, 2008, 8:03pm UTC](https://www.ruby-forum.com/t/has-many-questions/125632/1 "2008-01-10T20:03:14Z")

</div>

I am working on a project where I am uploading data about houses and  
need pictures to accompany it. I have a model for ‘housing’ and  
another one for picture.  
my housing class  
has\_many :picture

and my picture class  
belongs\_to :housing

My questions are

1. I want to use one form to create a new house with a bunch of  
pictures. how do I do this

2. a scaffold can generate the traversal of my housing table in my  
view, but how do I display the pictures.

3. I was told to use attachment\_fu, and the tutorial was great at  
telling me how to upload an image, but it didn’t show how to link an  
image to another model.

4. when I generate a scaffold via “ruby script/generate scaffold  
housing add\_housing” why don’t the forms contain the logic to upload  
pictures with the housing data.

I have been relying on books and google searches to get me started,  
but they have only discussed single models, and I haven’t found a good  
resource for doing what I need. Any help would be greatly appreciated.  
It doesn’t even have to be the answer, so long as it points me to  
something that will explain what is going on and help me get this done.

---

<div class="post-metadata">

**Author:** ![jvazquez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/858c86/32.png) [@jvazquez](https://www.ruby-forum.com/u/jvazquez)\
**Post date:** [January 10, 2008, 11:01pm UTC](https://www.ruby-forum.com/t/has-many-questions/125632/2 "2008-01-10T23:01:34Z")

</div>

jvazquez wrote:

> 1. I want to use one form to create a new house with a bunch of  
> pictures. how do I do this  
> Don’t. Create another action for that. It gets pain in the ass to handle  
> image post data on edits 🙂

> 1. a scaffold can generate the traversal of my housing table in my  
> view, but how do I display the pictures.  
> Use the docs, Luke! with attachment\_fu you do @picture.public\_filename.

> 1. I was told to use attachment\_fu, and the tutorial was great at  
> telling me how to upload an image, but it didn’t show how to link an  
> image to another model.  
> Well…  
> @picture = @housing.pictures.build(params[:picture])  
> @picture.save

> 1. when I generate a scaffold via “ruby script/generate scaffold  
> housing add\_housing” why don’t the forms contain the logic to upload  
> pictures with the housing data.  
> Don’t expect scaffold to be ‘oh mighty God’. It’s only for starters and  
> isn’t suited well for most cases in life.

> I have been relying on books and google searches to get me started,  
> but they have only discussed single models, and I haven’t found a good  
> resource for doing what I need. Any help would be greatly appreciated.  
> It doesn’t even have to be the answer, so long as it points me to  
> something that will explain what is going on and help me get this done.
