0

Help with this would be much appreciated. I am following along with railscasts episode 381 (http://railscasts.com/episodes/381-jquery-file-upload). I want to be able to upload multiple images. I am using the carrierwave gem. I'm a little unclear on what my actual problem is but I believe it is has something to do with loading the partial when the images are uploaded. Basically when I upload images in the browser console I get

"POST http://127.0.0.1:3000/slides 404 (Not Found)"

slides_controller

class SlidesController < ApplicationController

  def index
    @slide = Slide.all
  end

  def new
    @slide = Slide.new
  end

  def create
    @slide = Slide.create(params[:slide])
  #  @slide = Slide.new(params[:slide])
  #  if @slide.save
  #    flash[:notice] = "Successfully created slide."
  #    redirect_to :back
  #  else
  #    render :action => 'new'
  #  end
  end
end

_slides.htm.erb

<div class="slide">
  <%= link_to image_tag(slide.image_url(:thumb)), slide if slide.image? %>
  <div class="name"><%= slide.name %></div>
  <div class="actions">
    <%= link_to "edit", edit_painting_path(painting) %> |
    <%= link_to "remove", painting, :confirm => 'Are you sure?', :method => :delete %>
  </div>
</div>


  <%# Slide.where(:slideshow_id => @slideshow.id).find_each do |slide| %>
      <%#= slide.name %>
      <%#= image_tag slide.image_url(:thumb).to_s %>
  <%# end %>

create.js.erb

<% if @slide.new_record? %>
alert("Failed to upload painting: <%= j @slide.errors.full_messages.join(', ').html_safe %>");
<% else %>
$("#slides").append("<%= j render(@slide) %>");
<% end %>

slides.js.coffee

jQuery ->
  $('#new_slide').fileupload
    dataType: "script"
    add: (e, data) ->
      types = /(\.|\/)(gif|jpe?g|png)$/i
      file = data.files[0]
      if types.test(file.type) || types.test(file.name)
        data.context = $(tmpl("template-upload", file))
        $('#new_slide').append(data.context)
        data.submit()
      else
        alert("#{file.name} is not a gif, jpeg, or png image file")
    progress: (e, data) ->
      if data.context
        progress = parseInt(data.loaded / data.total * 100, 10)
        data.context.find('.bar').css('width', progress + '%')

I think it would be easier for you to just clone my repo since there are a lot of moving parts in my opinion.

https://github.com/iseabock/pretty_slideshow.git

Thanks for any help!

Update:

I finally got the railscast app to run and it is having the same problem as mine! I get the following error when I try to upload an image.

POST http://127.0.0.1:3000/paintings 404 (Not Found) 
bonum_cete
  • 4,730
  • 6
  • 32
  • 56
  • Is your server running on the same machine as your browser? – crowder Jul 07 '13 at 18:24
  • yeah, this is all local – bonum_cete Jul 07 '13 at 18:32
  • @isea why `create_old` when request is for create did you change the route if yes then please attach that info as well – Viren Jul 07 '13 at 18:34
  • crap, sorry forgot to push most recent - Pushed, sorry about that :/ - and edited above – bonum_cete Jul 07 '13 at 18:35
  • @isea hmm but i still cant find create.js.erb in you github repo if the link provided by you is correct – Viren Jul 07 '13 at 18:43
  • the link should be good. The create.js.erb is in views/slideshows/create.js.erb – bonum_cete Jul 07 '13 at 18:46
  • @isea why `slideshows` when the request is for `create` of `slides controller` also you havent specified in our slides create action that you want to use slideshows/create.js.erb by default will look for create.js.erb in the app/views/slides/ directory – Viren Jul 08 '13 at 06:30
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/33094/discussion-between-isea-and-viren) – bonum_cete Jul 08 '13 at 16:22

0 Answers0