Code generated by the 2 forms:
BELOW IS FORM WITH AJAX---update="imgmain":
<form action="/photos"
class="new photo"
enctype="multipart/form-data"
method="post"
onsubmit="Hobo.ajaxRequest(this, ['imgmain']); return false;">
<div class="hidden-fields">
<input id="page_path" name="page_path" type="hidden"
value="projects/new" />
<input name="authenticity_token" type="hidden" value="gA7U/
n2koCKgZxpPdJrQtQgeCwZXwu2m7hPnEZ++JYE=" />
<input id="photo_user_id" name="photo[user_id]" type="hidden"
value="14" />
</div>
<table class="field-list">
<tr>
<th class="mainimg-label">
Mainimg
</th>
<td class="mainimg-view">
<input class="mainimg-tag paperclip--attachment photo-
mainimg" id="photo_mainimg" name="photo[mainimg]" type="file" />
</td>
</tr>
</table>
<div class="actions">
<input class="button submit-button" type="submit" value="Save" />
</div>
<input name="after_submit" type="hidden" value="stay-here" />
</form>
The above does not save the image file, only a null object. Paperclip
does
not confirm the image was saved
BELOW IS FORM WITHOUT AJAX:
<form action="/photos"
class="new photo"
enctype="multipart/form-data"
method="post">
<div class="hidden-fields">
<input id="page_path" name="page_path" type="hidden"
value="projects/new" />
<input name="authenticity_token" type="hidden" value="gA7U/
n2koCKgZxpPdJrQtQgeCwZXwu2m7hPnEZ++JYE=" />
<input id="photo_user_id" name="photo[user_id]" type="hidden"
value="14" />
</div>
<table class="field-list">
<tr>
<th class="mainimg-label">
Mainimg
</th>
<td class="mainimg-view">
<input class="mainimg-tag paperclip--attachment photo-mainimg"
id="photo_mainimg" name="photo[mainimg]" type="file" />
</td>
</tr>
</table>
<div class="actions">
<input class="button submit-button" type="submit" value="Save" />
</div>
<input name="after_submit" type="hidden" value="stay-here" />
</form>
The above correctly saves the image file. Paperclip confirms the image
file was saved.
As you can see, they are identical except for:
onsubmit="Hobo.ajaxRequest(this, ['imgmain']); return false;"
So why is the above Hobo.ajaxRequest not reading the data from:
<input class="mainimg-tag paperclip--attachment photo-mainimg"
id="photo_mainimg" name="photo[mainimg]" type="file" />
?
The object is saved, but with Null fields, so for some reason the file
input field is empty when submitted with the
Hobo.ajaxRequest.
If this is really a bug, I would be interested in hearing alternate
solutions on updating my partial with the image file
that has just been uploaded. I have made a couple attempts, but they
broke the image file being saved.
Thanks for looking at this.
Cheers,
Jet
On Sep 1, 6:57 pm, blueHandTalking <[email protected]> wrote:
> I am getting back to an earlier post:
>
> "Understanding the Hobo <form>
>
> In that I mentioned being unable to get a form to post to the database
> when update is used with a Paperclip attachment. I am using the
> paperclip
> plugin and the paperclip_with_hobo plugin.
>
> When I use this form:
>
> <form with="&@project.photo" >
> <field-list: fields="mainimg" />
> <actions: />
> </form>
>
> The image is saved to the database, and I stay on the current page,
> because I have <after-submit stay-here /> in my form:
>
> <def tag="form" for="Photo">
> <form merge multipart param="default">
> param="photo-object"/> -->
> <error-messages param/>
> <field-list fields="mainimg,lwrimg,uprimg" param/>
> <div param="actions">
> <submit label="Save" param/> <!--<or-cancel param="cancel"/> --
>
> </div>
> <after-submit stay-here />
> </form>
> </def>
>
> I am trying to upload an image file and save it to d.b., and then load
> that image into a <div>
> on the page:
>
> <div id="imgmain" part="photomain">
> <%= render :partial => 'photos/mainphoto'%>
> </div>
>
> This is the partial:
>
> <%= (@photo == nil) ? '<img src="/images/main_tmp_display.jpg" />' :
> image_tag @photo.mainimg.url %>
>
> The syntax must be wrong for
>
> image_tag @photo.mainimg.url
>
> because it generates an error. I could use help on that.
>
> But back to the form issue, if I change the form to:
>
> <form with="&[email protected]" update="imgmain" >
> <field-list: fields="mainimg" />
> <actions: />
> </form>
>
> The image file does not get saved to the database.
> I appreciate the suggestions from Kevin and Bryan,
> but the examples you mentioned were not photos.
> Text updating does work. It appears that images do not.
> I believe that something is broken in regard to saving images,
> or there is some information I have missed. However, in the
>
> Notice that I am passing an instance of @project.photo to the form.
> I am creating that in the project controller. The form without the
> 'update' correctly saves the photo, but the form with update does not.
> Do I need to pass the @project.photo instance in the params hash?
>
> I am now using a dynamic <div> with a partial, so that would satisfy
> the
> condition Kevin mentioned about the content being static.
>
> What I am really looking for is a solution. If update is broken with
> images,
> what are some suggestions for an alternative? I have tried an rjs
> approach,
> but get directed to a 'photo' page instead of reloading the 'projects/
> new' page.
>
> If anyone has example or has been successful in uploading an image,
> then
> updating a partial with that image using Paperclip, I really would
> like to
> hear about it.
>
> Cheers,
>
> Jet
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---