Erwin
2011-May-16 10:06 UTC
Cannot get multipart => true , running well in my form when using remote => true
I have a simple form , with a file field = form_for (Clip.new), :html => {:multipart => true} , :remote => true , do |f| = f.hidden_field :user_id, {:value => current_user.id} = f.text_field :name = f.text_area :description = f.file_field :image = f.submit I18n.t(:add) generating the html code <form accept-charset="UTF-8" action="/en_GB/clips" class="new_clip" data-remote="true" enctype="multipart/form-data" id="new_clip" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="1ovVVdl+oh17phaR4ZVMc/ wZpL5v07YMBh+KsEqjTpk=" /></div> ... <p><input id="clip_image" name="clip[image]" type="file" /></p> <p><input id="clip_submit" name="commit" type="submit" value="Add" /></ p> </form> which seems to be OK ( compared to tutorial ...) but when if I check the params sent in my controller , I DON''T GET the clip[image] ... (rdb:9) params {"utf8"=>"✓", "authenticity_token"=>"1ovVVdl+oh17phaR4ZVMc/wZpL5v07YMBh +KsEqjTpk=", "clip"=>{"user_id"=>"9", "name"=>"test", "description"=>"testing image upload"}, "commit"=>"Add", "action"=>"create", "controller"=>"clips", "locale"=>"en_GB"} I should have the image upload data : "image"=>#<ActionDispatch::Http::UploadedFile:0... @original_filename="...", @content_type="image/jpeg", @headers=... @tempfile=#<File:/var/folders/NK/N...>> what could be wrong ? is the remote-true incompatible ? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Erwin
2011-May-16 10:12 UTC
Re: Cannot get multipart => true , running well in my form when using remote => true
[SOLVED .... well not solved but IMPOSSIBLE] seems cannot be done via Ajax ... need to review my design On 16 mai, 12:06, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote:> I have a simple form , with a file field > = form_for (Clip.new), :html => {:multipart => true} , :remote => > true , do |f| > = f.hidden_field :user_id, {:value => current_user.id} > = f.text_field :name > = f.text_area :description > = f.file_field :image > = f.submit I18n.t(:add) > > generating the html code > > <form accept-charset="UTF-8" action="/en_GB/clips" class="new_clip" > data-remote="true" enctype="multipart/form-data" id="new_clip" > method="post"><div style="margin:0;padding:0;display:inline"><input > name="utf8" type="hidden" value="✓" /><input > name="authenticity_token" type="hidden" value="1ovVVdl+oh17phaR4ZVMc/ > wZpL5v07YMBh+KsEqjTpk=" /></div> > ... > <p><input id="clip_image" name="clip[image]" type="file" /></p> > <p><input id="clip_submit" name="commit" type="submit" value="Add" /></ > p> > </form> > > which seems to be OK ( compared to tutorial ...) > > but when if I check the params sent in my controller , I DON''T GET > the clip[image] ... > > (rdb:9) params > {"utf8"=>"✓", "authenticity_token"=>"1ovVVdl+oh17phaR4ZVMc/wZpL5v07YMBh > +KsEqjTpk=", > "clip"=>{"user_id"=>"9", "name"=>"test", "description"=>"testing image > upload"}, > "commit"=>"Add", "action"=>"create", "controller"=>"clips", > "locale"=>"en_GB"} > > I should have the image upload data : > "image"=>#<ActionDispatch::Http::UploadedFile:0... > @original_filename="...", @content_type="image/jpeg", @headers=... > @tempfile=#<File:/var/folders/NK/N...>> > > what could be wrong ? is the remote-true incompatible ?-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Imran Latif
2011-May-16 12:01 UTC
Re: Re: Cannot get multipart => true , running well in my form when using remote => true
So, you want to upload Files (Images, PDFs) via Ajax. Well thats not impossible at all. We can upload files using Ajax. I have done it and it is working quite fine for me. Please! take a look at this tutorial. I'' am sure it will helps you a lot. http://khamsouk.souvanlasy.com/articles/ajax-file-uploads-in-rails-using-attachment_fu-and-responds_to_parent Thanks, On 16 May 2011 15:12, Erwin <yves_dufour-ee4meeAH724@public.gmane.org> wrote:> [SOLVED .... well not solved but IMPOSSIBLE] seems cannot be done > via Ajax ... need to review my design > > On 16 mai, 12:06, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote: > > I have a simple form , with a file field > > = form_for (Clip.new), :html => {:multipart => true} , :remote > => > > true , do |f| > > = f.hidden_field :user_id, {:value => current_user.id} > > = f.text_field :name > > = f.text_area :description > > = f.file_field :image > > = f.submit I18n.t(:add) > > > > generating the html code > > > > <form accept-charset="UTF-8" action="/en_GB/clips" class="new_clip" > > data-remote="true" enctype="multipart/form-data" id="new_clip" > > method="post"><div style="margin:0;padding:0;display:inline"><input > > name="utf8" type="hidden" value="✓" /><input > > name="authenticity_token" type="hidden" value="1ovVVdl+oh17phaR4ZVMc/ > > wZpL5v07YMBh+KsEqjTpk=" /></div> > > ... > > <p><input id="clip_image" name="clip[image]" type="file" /></p> > > <p><input id="clip_submit" name="commit" type="submit" value="Add" /></ > > p> > > </form> > > > > which seems to be OK ( compared to tutorial ...) > > > > but when if I check the params sent in my controller , I DON''T GET > > the clip[image] ... > > > > (rdb:9) params > > {"utf8"=>"✓", "authenticity_token"=>"1ovVVdl+oh17phaR4ZVMc/wZpL5v07YMBh > > +KsEqjTpk=", > > "clip"=>{"user_id"=>"9", "name"=>"test", "description"=>"testing image > > upload"}, > > "commit"=>"Add", "action"=>"create", "controller"=>"clips", > > "locale"=>"en_GB"} > > > > I should have the image upload data : > > "image"=>#<ActionDispatch::Http::UploadedFile:0... > > @original_filename="...", @content_type="image/jpeg", @headers=... > > @tempfile=#<File:/var/folders/NK/N...>> > > > > what could be wrong ? is the remote-true incompatible ? > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Imran Latif, Software Engineer NextBridge Pvt. Ltd, Lahore +92-322-6526002 (Mobile) http://www.nextbridge.pk -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.