javascript - jQuery File Upload: RailsCast for nested attributes and rails 4, file doesn't show, unless refreshed -


i'm following jquery file upload video railscast can't images show without refreshing page.

my photo being uploaded through form:

<%= simple_form_for @upload, html: { multipart: true, id: 'add_new_project_photos' } |f| %>   <%= f.simple_fields_for :project_images, projectimage.new, child_index: projectimage.new.object_id |ff| %>     <%= ff.file_field :photo, multiple: true, name: "project[project_images_attributes][][photo]" %>   <% end %> <% end %> 

i created create.js.erb file.

<% if @project.project_images.new_record? %>     alert("failed upload painting: <%= j @painting.errors.full_messages.join', ').html_safe %>"); <% else %>   $("#added_photos").append("<%= j render(@project) %>"); <% end %> 

my controller

class projectscontroller < applicationcontroller    #... other methods    def create     @project = project.new(trip_params)     @upload = project.create(trip_params)      if request.xhr?       redirect_to root_url     else       redirect_to :back     end      respond_to |format|       if @project.save          format.html { redirect_to @project, notice: 'project created.' }         format.json { render :show, status: :created, location: @project }       else         format.html { render :new }         format.json { render json: @project.errors, status: :unprocessable_entity }       end     end   end  end 

my coffee script file

jquery ->     $('#add_new_trip_photos').fileupload     datatype: "script" 

you need respond js well. in create method responding html , json

format.js 

should placed inside respond_to block


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -