12 2013 档案
摘要:1 Shop.each do |shop| 2 if !shop.comments.blank? 3 n = shop.comments.length 4 for i in 0..n-1 5 for j in i+1..n-1 6 if shop.comments[i].content == shop.comments[j].content 7 shop.comments[j].destroy 8 end 9 end10 end11 end...
阅读全文
摘要:category = Category.find_by(:name => "运动")category.brands.each do |brand| if brand.shops brand.shops.each do |shop| 5.times{ comment = shop.comments.new comment.created_at = rand((Time.now-2592000)..Time.now) comment.user = User.where(:robot => true).sample com = category.comment_sto
阅读全文
摘要:数据导出 mongoexport假设库里有一张user 表,里面有2 条记录,我们要将它导出> use my_mongodbswitched to db my_mongodb> db.user.find();{ "_id" : ObjectId("4f81a4a1779282ca68fd8a5a"), "uid" : 2, "username" : "Jerry", "age" : 100 }{ "_id" : ObjectId("4
阅读全文
摘要:Ruby代码1.#读文件 2.f = File.open("myfile.txt", "r") 3.f.each_line do|line| 4.puts "I read this line: #{line}"5.end#读文件f = File.open("myfile.txt", "r")f.each_line do|line|puts "I read this line: #{line}"endRuby代码1.File.foreach("myfile.txt&q
阅读全文