小编Ale*_*mes的帖子

在ruby 2.2.0中创建哈希的新方法

在ruby 2.2.0中你可以写这样的哈希:

hash = { 'new_possible_style': :of_hashes }
hash[:new_possible_style]  #=> :of_hashes
hash['new_possible_style'] #=> nil 
Run Code Online (Sandbox Code Playgroud)

我无法意识到实现这种风格的原因.如果我需要字符串作为键(例如,对于某些第三方库),我仍然需要使用旧式哈希.这个"功能"的用例是什么?核心开发人员为什么要添加这种风格?

提前致谢.

ruby hash

6
推荐指数
1
解决办法
1811
查看次数

如何使用paperclip-googledrive从谷歌驱动器下载文件?

我已经在谷歌驱动器上完成文件上传,但在下载时遇到错误:

ActionController::MissingFile: Cannot read file original_22_Wages372-817339(wages).pdf
Run Code Online (Sandbox Code Playgroud)

我认为它没有得到谷歌驱动器路径.

附件模型:

has_attached_file :doc, 
  storage: :google_drive,
  google_drive_credentials: "#{Rails.root}/config/google_drive.yml",
  google_drive_options: {
    public_folder_id: '0BwCp_aK6VhiaQmh5TG9Qbm0zcDQ',
    path: proc { |style| "#{style}_#{id}_#{doc.original_filename}" }
  }
Run Code Online (Sandbox Code Playgroud)

控制器:

 attachment = Attachment.find(params[:id])      
 send_file attachment.doc.path(:original), 
   filename: attachment.doc_file_name, 
   type: attachment.doc_content_type, 
   stream: 'true', 
   x_sendfile: true
Run Code Online (Sandbox Code Playgroud)

提前致谢

ruby ruby-on-rails google-drive-api ruby-on-rails-4

5
推荐指数
1
解决办法
933
查看次数

如何在sublime-text-2中运行ruby文件

当我按ctrl + b运行简单的代码,如:

puts "asdasd"
Run Code Online (Sandbox Code Playgroud)

结果是空白字段.Ruby路径是/home/yukke/.rvm/rubies/default/bin/ruby和ruby -v => ruby​​ 1.9.3p194(2012-04-20 revision 35410)[x86_64-linux].

所以我试着改变Ruby.sublime-build

{
    "cmd": ["/home/yukke/.rvm/rubies/default/bin/ruby", "-u","$file"],
    "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
    "selector": "source.ruby"
}
Run Code Online (Sandbox Code Playgroud)

但它没有改变任何东西.请帮我解决这个问题.

ruby ubuntu sublimetext2

2
推荐指数
1
解决办法
4331
查看次数