0

对此的帮助将不胜感激。我正在关注 railscasts 第 381 集(http://railscasts.com/episodes/381-jquery-file-upload)。我希望能够上传多张图片。我正在使用carrierwave gem。我有点不清楚我的实际问题是什么,但我相信这与上传图像时加载部分有关。基本上,当我在浏览器控制台中上传图像时,我得到

"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 %>

创建.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 + '%')

我认为克隆我的 repo 会更容易,因为我认为有很多活动部分。

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

谢谢你的帮助!

更新:

我终于让 railscast 应用程序运行了,它和我的问题一样!尝试上传图片时出现以下错误。

POST http://127.0.0.1:3000/paintings 404 (Not Found) 
4

0 回答 0