Hi Arve,

Sory for the late response. I'm glad sgagility worked for you as an example. I've looked at your code and it looks very nice.

From your explanation, you might wanna take a look at using a many-to-many relatinship between projects and project files, but I'm not really sure if you need that. You have an example in the agility tutorial if you do.

Regards,
Ignacio

El 26/10/12 12:30, Arve Voldsund escribió:
Hi Ignacio,

The sgagility project has been tremendous help for me in trying to get a grip 
of how things work. I find it a bit hard to understand all the flexibility that 
lies within hobo, and sgagility sort of opened up a few doors so to say. I 
first started using rails when I found Hobo and was pretty fresh at Ruby as 
well, so there has been a few things to sort out, but it is coming together now.

To the point:

What I wanted was to have a project that is merely a description of what kind 
of data the project represents, and then files should be attached to this 
project as a set belonging to a projectfile. In other words: The projectfile 
should be a container that keeps track of which uploads that belong to a 
certain project.

I understood from your comments (thanks) that I missed an abstraction layer, 
and changed the relationships as follows:

Project has has many projectfiles and projectfiles has many uploads.

The idea behind this is that any project can be created and assigned to any set 
of projectfiles, and then the project needs to own the projectfile container 
which again owns the uploads.

The uploads are created from the projectfile edit-page (since it is required to 
create a projectfile before uploading).

It is all working now, and the controller for projectfiles looks like this, and 
I'd be glad to get feedback on it if it should be done in another way:

class ProjectfilesController < ApplicationController

   hobo_model_controller

   auto_actions :all

    def index
      hobo_index do
        @projectfile = Projectfile.new
      end
    end

   def show
     hobo_show do
       if params[:style]
         send_file @projectfile.prattach.path(params[:style])
       else
         render
       end
     end
   end

   def update
     hobo_update do
       Upload.create(
            :file_name =>this.prattach_file_name,
            :file_type =>this.prattach_content_type,
            :file_size =>this.prattach_file_size,
             :file_created =>this.prattach_updated_at,
             :projectfile_id => this.id
             )

       respond_to do |format|
         format.js   { hobo_ajax_response }
         format.html { redirect_to @projectfile }
       end
     end
   end

end



Best,
Arve

On Oct 25, 2012, at 9:09 PM, Ignacio Huerta <[email protected]> wrote:

Hi Arve,

I'm a bit confused about your models and relationships. If you want to
have several attachments to a project, then you are gonna need a 1-N
relationship:

  A project has many projectfiles
  A projectfile belongs to one project

Maybe I got the idea wrong, but you are trying to create a multiple
file upload in the edit page of a projectfile. I think it would make
more sense to do it in the edit page of the project. Or maybe I didn't
understand your relationships :P.

By the way, there's a working example of multiple file upload (you can
drag 3 attachments in the show of a project) in here:
https://github.com/suyccom/sgagility . I'm afraid I haven't taken much
care of that app (I plan to replace it soon with a cleaner one), and
some parts might be broken, but it might serve as an example.

Regards,
Ignacio

El 24/10/12 00:22, Arve Voldsund escribió:
I struggle a bit with a create method for a model with multiple
file upload, and could really need some advice on this.

Basically I want the user to create a new projectfile (that's the
model name) and assign it to a project. This is trivial.

Then, in the edit-page for that particular projectfile there is a
file upload using the jQuery file upload plugin which allows
multiple files. Files upload just fine, but only one file will be
assigned to the projectfile in the database. I understand why, but
I do not quite get how to fix it in the create method.


Arve


-- You received this message because you are subscribed to the
Google Groups "Hobo Users" group. To view this discussion on the
web visit
https://groups.google.com/d/msg/hobousers/-/9skhe0yG4hUJ. To post
to this group, send email to [email protected]. To
unsubscribe from this group, send email to
[email protected]. For more options, visit
this group at http://groups.google.com/group/hobousers?hl=en.

--
Ignacio Huerta Arteche
http://www.ihuerta.net
Teléfono: 0034 645 70 77 35
Email realizado con software libre

--
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.



--
Ignacio Huerta Arteche
http://www.ihuerta.net
Teléfono: 0034 645 70 77 35
Email realizado con software libre

--
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to