我將內容上傳到託管的CMS。他們提供了一個Ruby Gem,允許我以編程方式上傳大量內容。我能夠通過編輯其中一個腳本來上傳我的內容,但無法通過上傳將腳本包含在我的文件中。這是我使用成功的腳本:合併Ruby腳本
#!/usr/bin/env ruby -rubygems
require File.join(File.dirname(__FILE__), 'authentication')
require "csv" # faster_csv (ruby 1.9)
lines = CSV.read(File.join(File.dirname(__FILE__), 'karaoke.csv')) # Exported an Excel file as CSV
lines.slice!(0) # remove header line
collection = StorageRoom::Collection.find('my collection ID')
Song = collection.entry_class
lines.each do |row|
karaoke = Song.new(:artist => row[0], :song => row[1], :genre => row[2])
if karaoke.save
puts "Misuero Karaoke Latino saved: #{karaoke.artist}, #{karaoke.song}, #{karaoke.genre} "
else
puts "Misuero Karaoke Latino could not be saved: #{karaoke.errors.join(', ')}"
end
end
這是腳本,按照他們的榜樣,會做文件上傳:
#!/usr/bin/env ruby -rubygems
require File.join(File.dirname(__FILE__), 'authentication')
path = ::File.expand_path(File.join(File.dirname(__FILE__) + '..', 'spec', 'fixtures', 'image.png'))
collection = StorageRoom::Collection.find('my collection ID')
# Upload File
entry = collection.entry_class.new(:name => "StorageRoom Logo", :file => StorageRoom::File.new_with_filename(path))
if entry.save
puts "Entry saved (#{entry[:@url]})"
puts "URL of the uploaded file is #{entry.image.url}"
puts "URL of the automatically generated thumbnail is #{entry.image.url(:thumbnail)}" # Multiple Image Versions can be specified in the interface
else
puts "Entry could not be saved: #{entry.errors.join(', ')}"
end
我想組合兩個腳本,所以我只跑一個,但我不能讓文件上傳部分工作。我正嘗試上傳.mov。文件在哪裏與腳本有關?我怎樣才能使它們正確命名?我將如何編輯腳本,以便它可以處理多個文件?我該如何合併腳本?
甜。什麼規格燈具部分是什麼意思? – hanleyhansen 2012-04-03 19:05:57
我試過這個http://pastebin.com/Rb3Asm2v,但我得到一個錯誤,說: import_csv.rb:22:語法錯誤,意外的keyword_end,期待')'不知道這意味着什麼。 – hanleyhansen 2012-04-03 23:08:25
'your_rails_root/spec/fixtures/image.png'是一個用於測試的示例圖片。 看起來你在第15行有一個錯字,這意味着你的文件名字符串沒有關閉。嘗試'... StorageRoom :: File.new_with_filename(「#{karaoke.artist}#{karaoke.song} .mov」))'。 – RobinGower 2012-04-03 23:48:23