2015-04-14 98 views
1

我想上傳我的圖像上cloudinary使用jquery文件上傳寶石。使用cloudinary(attachinary)與軌道加jQuery文件上傳

我跟着本教程使用attachinary來做這件事,但我認爲我錯過了一些東西或者教程不完整,因爲在跟着它之後,我確實得到了一個帶有按鈕的表單,可以在cloudinary上上傳多個圖片,但是jquery文件用進度條上傳用戶界面並沒有得到顯示,我只是一個簡單的按鈕,選擇文件作爲標籤。

請幫我理解我哪裏出了問題,以及如何使用進度條獲得jQuery文件上傳gem的用戶界面。

,我跟着該教程是 https://github.com/assembler/attachinary

這裏是我的文件

/*routes.rb*/ 
Rails.application.routes.draw do 


    root 'prime_petz#home' 

    get 'prime_petz/home' 

    get 'prime_petz/about' 

    get 'prime_petz/contact' 

    resources :listings 
    mount Attachinary::Engine => "/attachinary" 
end 

/Listing.rb/

class Listing < ActiveRecord::Base 
    has_attachments :photos, maximum: 10 
end 

/的application.js/

//= require jquery 
//= require jquery_ujs 
//= require turbolinks 
// Loads all Semantic javascripts 
//= require semantic-ui 
//= require jquery-fileupload 
//= require jquery-fileupload/vendor/tmpl 
//= require cloudinary/jquery.cloudinary 


//= require attachinary 
//= require_tree 

/new.html.erb/

<%=form_for @listing, :html=> { class:'ui form centered black segment' } do |f|%> 
<div class="field"> 
    <%= f.attachinary_file_field :photos,class:'ui button gallery' %> 
    </div> 
<%end%> 

/的Gemfile/

source 'https://rubygems.org' 


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 
gem 'rails', '4.1.1' 
# Use sqlite3 as the database for Active Record 
gem 'sqlite3' 
# Use SCSS for stylesheets 
gem 'sass-rails', '~> 4.0.3' 
# Use Uglifier as compressor for JavaScript assets 
gem 'uglifier', '>= 1.3.0' 
# Use CoffeeScript for .js.coffee assets and views 
gem 'coffee-rails', '~> 4.0.0' 
# See https://github.com/sstephenson/execjs#readme for more supported runtimes 
# gem 'therubyracer', platforms: :ruby 

# Use jquery as the JavaScript library 
gem 'cloudinary' 
gem 'jquery-ui-rails' 
gem 'attachinary' 
gem 'jquery-rails' 
gem "jquery-fileupload-rails" 
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 
gem 'turbolinks' 
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 
gem 'jbuilder', '~> 2.0' 
# bundle exec rake doc:rails generates the API under doc/api. 
gem 'sdoc', '~> 0.4.0',   group: :doc 

gem 'semantic-ui-sass', github: 'doabit/semantic-ui-sass', branch: 'v1.0beta' 


# Use ActiveModel has_secure_password 
# gem 'bcrypt', '~> 3.1.7' 

# Use unicorn as the app server 
# gem 'unicorn' 

# Use Capistrano for deployment 
# gem 'capistrano-rails', group: :development 

# Use debugger 
# gem 'debugger', group: [:development, :test] 

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 
gem 'tzinfo-data', platforms: [:mingw, :mswin] 

/listing.js.coffee/

jQuery -> 

$('#new_listing').fileupload 
dataType:"script" 
add: (e, data) -> 
data.context = $(tmpl("template-upload", data.files[0])) 
$('#new_listing').append(data.context) 

progress: (e, data) -> 
if data.context 
    progress = parseInt(data.loaded/data.total * 100, 10) 
    data.context.find('.bar').css('width', progress + '%') 

用這個我能夠查看的只是一個簡單的ChooseFiles按鈕。

+0

嘿,你怎麼終於得到這個工作? – user2635088

回答

0

你確定你在窗體視圖中包含了下面的jQuery代碼嗎?

$('.attachinary-input').attachinary(); 
+0

是的,我也是這麼做的,仍然沒有成功 –

+0

控制檯中是否有任何jQuery錯誤(在瀏覽器的「開發工具」下)?你可以分享一個網址到一個實況網頁,這是演示嗎? –

+0

如果您希望我可以使用團隊查看器或skype與您分享我的屏幕。並且關於控制檯上的任何錯誤,不會有任何錯誤。 –

0

按照attachinary自述,

Attachinary jQuery插件是基於jQuery的文件上傳插件,但沒有任何花哨的UI(它離開它你來裝飾它)。