Ruby on Rails Friday, April 30, 2010


I am stucked at some major issue with the AjaxForm and render_to_string.

I am using AjaxForm for uploading images with other details since the Ajax Upload library isn't even using Ajax. So once the form is submitted i need to call a partial and return it in a json format. but the problem is that the render_to_string is not working at all. In case if i am returning simple string then it's working fine.

reference http://jquery.malsup.com/form/#file-upload

#server Ruby on rails
def some_action
  respond_to do |format|
    @html = render_to_string(:partial => "form.html.erb", :object => [@obj1, @obj2])
    json = { :success => "Added successfully", :html => @html }
    format.html { render :json => json }
  end
end

#client side
$("#upload").ajaxForm({
        dataType: "json",
        success: function(response) {
          console.log(response);
          console.log(response.html);
  });
return false;
});

Thanks for any help
Abhis

--
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@googlegroups.com.
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.

No comments:

Post a Comment