Forum: Ruby on Rails acts_as_attachment - 1 form

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4bb313af528d968c3a35e8208ecd287b?d=identicon&s=25 Shagymoe (Guest)
on 2007-03-13 18:05
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
8acba6d057b3f0c2c16cca95ad36881b?d=identicon&s=25 Bakki Kudva (bakki)
on 2007-03-13 20:03
(Received via mailing list)
On 3/13/07, Shagymoe <rails-mailing-list@andreas-s.net> 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?
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2007-03-13 21:07
(Received via mailing list)
On 3/13/07, Shagymoe <rails-mailing-list@andreas-s.net> 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 Olson
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
This topic is locked and can not be replied to.