# Acts\_as\_attachment - 1 form

**URL:** <https://www.ruby-forum.com/t/acts-as-attachment-1-form/88705>\
**Category:** Rails\
**Created:** [March 13, 2007, 6:05pm UTC](https://www.ruby-forum.com/t/acts-as-attachment-1-form/88705 "2007-03-13T18:05:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shagymoe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ebca7d/32.png) [@shagymoe](https://www.ruby-forum.com/u/shagymoe)\
**Post date:** [March 13, 2007, 6:05pm UTC](https://www.ruby-forum.com/t/acts-as-attachment-1-form/88705/1 "2007-03-13T18:05:01Z")

</div>

Hi all, I’ve asked some seriously detailed questions about this in other  
forums and you’d think I’d set some user preference to “set my posts to  
invisible”. LOL

When it comes right down to it, my question is simple.

Can you use 1 form to save an object and that object’s attachment?. All  
of the examples I’ve seen (all 2 of them) show the controller/model/view  
for DVD Covers, but not for DVDs. Why would you have two actions for  
this? One page to create the DVD and another to create the DVD Cover?  
It seems silly to me. I want to create/upload and validate both at the  
same time, in the same form. IS THIS POSSIBLE? If so, do you have any  
example code? Am I making sense here? Isn’t it better to input all of  
the information for the DVD and upload the cover on the same page?

I have other issues with this plugin, but I thought I’d start here. (for  
instance, I’ve specified file\_system\_path =\> ‘public/files’ and it is  
still looking for the db\_files table…)

AAAAAGGGHH,

Shagy

---

<div class="post-metadata">

**Author:** ![shagymoe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ebca7d/32.png) [@shagymoe](https://www.ruby-forum.com/u/shagymoe)\
**Post date:** [March 13, 2007, 8:03pm UTC](https://www.ruby-forum.com/t/acts-as-attachment-1-form/88705/2 "2007-03-13T20:03:22Z")

</div>

On 3/13/07, Shagymoe [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Can you use 1 form to save an object and that object’s attachment?. All

Yes. In addition to the mandatory fields that aaa needs you can define  
as many additional fields, validations etc to your model. SO you can  
have DVD and DVD attachment in the same form.

> I have other issues with this plugin, but I thought I’d start here. (for  
> instance, I’ve specified file\_system\_path =\> ‘public/files’ and it is  
> still looking for the db\_files table…)

Do you also have :storage =\> :file\_system specified?

---

<div class="post-metadata">

**Author:** ![shagymoe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ebca7d/32.png) [@shagymoe](https://www.ruby-forum.com/u/shagymoe)\
**Post date:** [March 13, 2007, 9:07pm UTC](https://www.ruby-forum.com/t/acts-as-attachment-1-form/88705/3 "2007-03-13T21:07:41Z")

</div>

On 3/13/07, Shagymoe [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> this? One page to create the DVD and another to create the DVD Cover?  
> It seems silly to me. I want to create/upload and validate both at the  
> same time, in the same form. IS THIS POSSIBLE? If so, do you have any  
> example code? Am I making sense here? Isn’t it better to input all of  
> the information for the DVD and upload the cover on the same page?

Sure. It’d work like creating to of any other models in the same  
controller action:

Something like that, though you can get more creative and create the  
cover in an after\_save callback of the dvd if you want.

def create  
@dvd = Dvd.new(params[:dvd]  
@dvd\_cover = DvdCover.new(params[:dvd\_cover])  
Dvd.transaction do  
@dvd.save!  
@dvd\_cover.dvd = @dvd  
@dvd\_cover.save!  
end  
end

> I have other issues with this plugin, but I thought I’d start here. (for  
> instance, I’ve specified file\_system\_path =\> ‘public/files’ and it is  
> still looking for the db\_files table…)

That’s because the key is :path\_prefix, not :file\_system\_path.  
:file\_system\_path still works though, it’s a legacy option. Here’s  
the logic you’re looking for:

options[:storage] ||= (options[:file\_system\_path] ||  
options[:path\_prefix]) ? :file\_system : :db\_file

So, you may have to write some tests to see why that’s not working.  
I’ve never seen any issues with that though.

> AAAAAGGGHH,

Settle down, generate the rdocs from the source, or just read the  
source. It’s not that big 🙂

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)
