我将内容上传到托管的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