I am trying to upload an image in RAILS 3 using AJAX form submission , this
is my code :
<%= form_for(:image, :remote => true, :url => {:controller=>
'questions',:action => 'upload'}, :html => {:id=>'qimage_upload'}) do |f| %>
<%= f.file_field :image, :onchange => "$(this).parents('form').submit();"
%>
<% end %>
I have set the :remote => true option above and submitting the form with an
onchange event . I have the following code in controller :
def upload
if request.xhr?
@image = Image.new(params[:image])
@image.save
respond_to do |format|
format.js { render :layout=>false }
end
else
render :text => 'Request Wasnt AJAX'
endend
If I change the field to text in the form , the request is AJAX(everything
else remaining same) but with an image field the request is always AJAX . I
have included 'jquery' and 'jquery_ujs' in my application.js file as well.
My action renders the text everytime , the request does not seem to be AJAX
style despite the remote tag being set (it appears correctly even in the
final HTML). I can't figure out where I am going wrong with this . I have
tested it in the latest browser version of FF and Chrome , so I don't think
it's a browser issue. Any ideas ?
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/IoBk58iurt0J.
For more options, visit https://groups.google.com/groups/opt_out.