Uploading a file in Rails

Update 2018 While everything written below still holds true, Rails 5.2 now includes active_storage, which allows stuff like uploading directly to S3 (or other cloud storage services), image transformations, etc. You should check out the rails guide and decide for yourself what fits your needs. While there are plenty of gems that solve file uploading pretty nicely (see https://www.ruby-toolbox.com/categories/rails_file_uploads for … Read more

Meaning of #{ } in Ruby?

Why This Is a Good Question This is a tough question to Google for unless you know the right search terms. The #{} operator technically performs expression substitution inside a string literal. The Answer The #{} literal is the operator used for interpolation inside double-quoted strings the same way that the backticks or $() construct would be used in Bash. From a practical point of view, … Read more

Getting error: dyld: Symbol not found: _clock_gettime

I was getting the same dyld: Symbol not found: _clock_gettime error message during an attempted install of ruby 2.3.1 on El Capitan. The advice here to run xcode-select –install and allow the xcode command line tools to reinstall solved that issue for me. If you’re using that version of OS X perhaps it may help you as well?

Ruby 2.0.0p0 IRB warning: “DL is deprecated, please use Fiddle”

The message you received is common when you have ruby 2.0.0p0 (2013-02-24) on top of Windows. The message “DL is deprecated, please use Fiddle” is not an error; it’s only a warning. The source is the Deprecation notice for DL introduced some time ago in dl.rb ( see revisions/37910 ). On Windows the lib/ruby/site_ruby/2.0.0/readline.rb file … Read more

What is the best way to convert an array to a hash in Ruby

NOTE: For a concise and efficient solution, please see Marc-AndrĂ© Lafortune’s answer below. This answer was originally offered as an alternative to approaches using flatten, which were the most highly upvoted at the time of writing. I should have clarified that I didn’t intend to present this example as a best practice or an efficient … Read more