Hi there,
I have a solution for this,
but I don''t like the way it returns its result.
> listing.attach_file(file, description, category_ids)
-> ["the file is not a valid type", "category:17
doesn''t exist"]
in the case that the attachment failed
or
> listing.attach_file(file, description, category_ids)
-> []
in the case of success.
here are the models;
class Listing
has_many :listing_attachments
has_many :attachments, :through => :listing_attachments
end
class ListingAttachment
belongs_to :listing
belongs_to :attachment
# the only interesting feature of this is that it has a :description
field
end
class Attachment
has_many :attachment_categories
has_many :categories, :through => :attachment_categories
file_column :file_name
end
class AttachmentCategory
...
end
class Category
...
end
I have the following requirements for the function:
1. take 4 inputs: a Listing, an uploaded file, the description,
category_ids
2. create an Attachment with the given "uploaded file"
3. give that attachment the desired categories
4. link this to the Listing
5. ensure the :listing_attachment has the "description" set.
My current solution is the following;
class Listing
def attach_file(file, description, category_ids)
# do it
# stick any validation errors into an array
return errors=[]
end
end
but it feels dirty returning an "error_array"
and "return false, errors=[]", feels even worse.
hmm..
MatthewRudy
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---