On a side note, it's more beneficial if you break long, multi-part
questions like this into smaller chunks.  That way it's clearer what a
discussion talks about and you're more likely to get a good answer.

1. When you save a model with unsaved associations, the associations
will be saved at the same time.

2. I wasn't able to tell what the question was in that.  Are you
looking for help saving the parameters from the photo?  How to name
it?  How to make the page flow the way you want?

3. After submit creates a hidden input with the path.  What I find
helpful when dealing with controller actions is to throw in a raise
variable.inspect to be able to see what's what at a given point.  You
might want to do a raise params.inspect at the beginning of your
controller action to see just what parameters are available to you and
what form they're in.  Hobo render/redirect logic checks if the
parameter is set and goes to that if the action is successful.

4. Normally parameters are nested hashes, so params[:project]
[:photo].  Best bet is to use trick from 3 when you're starting out to
see what you've got to use.

On Sep 8, 9:06 pm, blueHandTalking <[email protected]> wrote:
> I have a project with the following relationships:
>
>    class Project < ActiveRecord::Base
>       has_one   :photo
>       has_one   :project_detail
>
>    class Photo < ActiveRecord::Base
>       belongs_to   :project, :accessible => true, :creator => true
>
>    class ProjectDetail < ActiveRecord::Base
>       belongs_to   :project, :accessible => true, :creator => true
>
> I am trying to create a page with 4 forms, 3 to upload photos with
> paperclip,  and one to upload project_details.
>
> The photo form is defined with <after-submit stay-here />
>
> The page is created by the ProjectsController. In that I currently
> have
> been creating the following in  'def new':
>
>     @project = Project.new
>     @project.build_photo
>     @project.photo.save    (If I save project, does it also save
> project.photo?)
>     @project.photo_id = @project.photo.id  (does rails do this
> automatically?)
>     @project.build_project_detail
>     @project.project_detail.save
>
>     @project.project_detail_id = @project.project_detail.id  (does
> rails do this automatically?)
>     @project.save
>     redirect_to :action => "edit", :id => @project.id, :photo_id =>
> @project.photo_id, :project_detail_id => @project.project_detail_id
>
> The above seems very redundant and unnecessary. I would like to know a
> much better way of going about
> this. The reason for saving and redirecting to edit was so that the
> project id would be created when I upload
> a photo.
>
> The page is supposed to function by being able to upload the 3 images,
> and then upload the project_details.
> Since AJAX does not support file uploads, I am going to try and
> implement an 'Ajaxy' solution using iframes and the
> "responds_to_parent" plugin. However, first I would like to know
> answers to the following:
>
> 1) What is a better approach than the one above for setting up the new
> project  page?
> 2) In my photo form I am passing @project.photo. This does get handled
> by the photo controller, but the
>     following does not work in the PhotosController:
>
>     @project = Project.find(params[:project_id])
>     @project.photo.update_attributes(params[:photo])
>
>     A hidden field in the form is:
>
>       <input id="photo_project_id" type="hidden" value="142"
> name="photo[project_id]"/>
>
> The above does not work.
>
>   So what is the correct way to achieve the above?
>
>   This does work: �...@photo = Photo.new(params[:photo])  ....but is not
> what I want.
>
>   The photo model has fields for 3 photos, so I need to use the same
> record for all
>   3 uploads, and stay on the new project page until the
> project_details form is posted.
>   So whenever I return from posting a photo, I somehow need the photo
> controller to
>   make �...@project available to the reloaded project edit page. How
> should this be done?
>   Do I need to think about using session, or can this be simply done
> in the fashion I
>   am attempting, but not quite getting?
>
> 3) In the photos controller, what is the correct way to redirect to
> the page I just came from.
>
>     <after-submit stay-here />  does not work if I define 'create'
>
>     In the Projects controller I used:
>
>     redirect_to :action => "edit", :id => @project.id, :photo_id =>
> @project.photo_id, :project_detail_id => @project.project_detail_id
>
>    ...which worked great.  I thought I could just change that to
> "projects/edit, but no. Something like
>       :url => (page I just came from)??
>
> Thanks,
>
>     Jet
>
> Oh, and a bonus question.   If I have the above mentioned relationship
> with project and photo,
> and I create an instance in the projects controller: �[email protected]
>
> how would I access the photo data in the returned params hash from a
> form,
> e.g. to access the project data (params[:project])
>
> would accessing photo part be (params[:project => :photo])
>
> ...and an individual element (params[:project => :photo
> => :name])  ???
--~--~---------~--~----~------------~-------~--~----~
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