我一直在研究由Ryan提出的名爲Jquery文件上傳的screencast pro。不過每次我輸入圖片都不會上傳。我不知道我在這裏做錯了我的代碼。我使用谷歌並沒有嘗試上載它,但它似乎並沒有被做任何事情Jquery基本文件上傳
的Javascript 的application.js
//= require jquery
//= require jquery_ujs
//= require jquery-fileupload/basic
//= require jquery-fileupload/vendor/tmpl
//= require_tree .
painting.js.coffee
jQuery ->
$('#new_painting').fileupload
查看 _form.html.erb
<%= form_for @painting, :html => {:multipart => true} do |f| %>
<div class="field">
<%= f.hidden_field :galley_id %>
</div>
<div class="field">
<%= f.label :image %><br />
<%= f.file_field :image %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
index.html.erb
繪畫廊
<%= form_for Painting.new do |f| %>
<%= f.label :image, "Upload paintings:" %>
<%= f.file_field :image, multiple: true, name: "painting[image]" %>
<% end %>
show.html.erb
<p><%= image_tag @painting.image_url %></p>
<p>
<%= link_to "Edit", edit_painting_path(@painting) %> |
<%= link_to "Destroy", @painting, :confirm => 'Are you sure?', :method => :delete %> |
<%= link_to "Back to Paintings", paintings_path %>
</p>
控制器
def index
@paintings = Painting.all
end
def show
@painting = Painting.find(params[:id])
end
def new
@painting = Painting.new
end
def create
@painting = Painting.create(params[:painting])
end
def edit
@painting = Painting.find(params[:id])
end
def update
@painting = Painting.find(params[:id])
if @painting.update_attributes(params[:painting])
redirect_to paintings_url, notice: "Painting was successfully updated."
else
render :edit
end
end
def destroy
@painting = Painting.find(params[:id])
@painting.destroy
redirect_to paintings_url, notice: "Painting was successfully destroyed."
end
模型
attr_accessible :image
mount_uploader :image, ImageUploader
我的主要問題是,當涉及到上傳任何圖片,它只是沒有一個提交按鈕,不知道如何使它工作,我錯過了什麼?