I am trying to upload an image using asynchronous submission of form , this is my Rails HTML :
<%= form_for(:image, :url => {:controller=> 'questions',:action => 'upload_Qimage'}, :html => {:id=>'qimage_upload'}) do |f| %>
<%= f.file_field :image, :onchange => " return uploadImage() ; " %>
<%= f.hidden_field :id , :value => Digest::MD5.hexdigest((current_user.id + Time.now.to_i).to_s )[0,7] %>
<% end %>
This is my js function uploadImage() :
function uploadImage ()
{
$('#qimage_upload').submit() ;
$('#qimage_upload').submit( function() {
return false ;
}
Ignore the ajax code inside the submit function , I cannot get the second alert even after commenting it out . I have been working on this all day now and can't figure out what's wrong with it .
UPDATE : Please note the update in the code above , using a simple submit() with no callback works but it does not serve my purpose as it tries to render a view for the action . Is this a jqeury version issue ?
Second Update : This is what my controller action looks like :
def upload_Qimage
@image = Image.new(params[:image])
@image.save
end
No matter what I try with the jquery and html , it still tries to render a view . The file is saved with the current updated js but it still tries to render a view when I want it do nothing or rather just return some data (not a partial render , just data)