Take the 2-minute tour ×

I'm following Railscasts Episode #381 to set up jQuery File Upload to upload files to the server on Rails 3.

Right I have it fully functional using jQuery File Upload + Paperclip.

Works fine. But I don't quite understand how to show the pictuers that just were uploaded without reloading the page.

The author of RailsCast says "just change the controller so it looks like this"

  def create
    @picture = Picture.create(params[:picture])

(did that)

"and then make a create.js.erb template with following code"

<% if @picture.new_record? %>
    alert("Failed to upload picture");
<% else %>
    $("body").append("<% j render(@picture) %>");
<% end %>

(I don't understand to which folder I have to put it. Tried into app/views/pictures/ but it is not being triggered).

So I guess the question is - How do I trigger a "create.js.erb" when new picture is submitted.


share|improve this question

1 Answer 1

solved it like so:

<% if @picture.new_record? %>
    alert("Failed to upload picture");
<% else %>
    $("table").append('<tr><td><%= image_tag @picture.file.url(:small) %></td></tr>');
<% end %>
share|improve this answer

Your Answer


