Check out
- https://github.com/thoughtbot/guides/tree/master/style
- https://github.com/styleguide
- https://gist.github.com/bobbygrace/9e961e8982f42eb91b80
The following are key points
Check out
The following are key points
module HandleFunkyFormats | |
extend ActiveSupport::Concern | |
included do | |
rescue_from ActionView::MissingTemplate do | |
if params[:format] | |
redirect_to format: nil | |
end | |
end | |
end |
require 'net/https' | |
require 'uri' | |
class RunDMS | |
def self.snitch(id, options={}, &block) | |
dead_man = new(id, options) | |
block.call | |
dead_man.snitch | |
end |
Restores the generation of non-digest assets from Rails 3. This is essential for when those assets must be referenced outside of Rails. Maybe some of your app in in another language, or maybe some of your JavaScript is dynamically and conditionally loaded.
Compile your assets with the regular task:
The aim of this post is to guide the reader through the process of installing ruby 2.0.0 into rbenv with dtrace probes enabled. As rbenv uses ruby-build, which currently downloads and compiles a copy of openssl rather than using the one maintained and updated in homebrew i prefer to use the homebrew one.
Note that you MUST install xcode before installing anything, then install homebrew, and lastly install openssl, via homebrew as follows.
brew install openssl
Next to overcome the fact that OSX doesn't have an openssl ca certificate bundle, use the following brew to create and maintain one using the CA certs stored in your keychain.
# Stick this in lib/tasks/assets.rake or similar | |
# | |
# A bug was introduced in rails in 7f1a666d causing the whole application cache | |
# to be cleared everytime a precompile is run, but it is not neccesary and just | |
# slows down precompiling. | |
# | |
# Secondary consequences are the clearing of the whole cache, which if using | |
# the default file cache could cause an application level performance hit. | |
# | |
# This is already fixed in sprockets-rails for rails 4, but we patch here for |
We've seen lots of Ruby feature requests about converting an Enumerable to a Hash: to_h
, map_hash
, map_to
, each_with_hash
, etc. Let's look at one common, simple case of this.
Building a key/value mapping from a collection of keys is awkward. We commonly see Hash[*collection.map { |element| [element, calculate(element)] }]
or collection.each_with_object({}) { |element, hash| hash[element] = calculate(element) }
. Both are verbose. They require boilerplate code that's not relevant to the programmer's intent: to associate an enumerable of keys with calculated values.
Ruby has the idea of an association already: a key and value paired together. It's used by Array#assoc
to look up a value from a list of pairs and by Hash#assoc
to return a key/value pair. Building up a mapping of key/value pairs is associating keys with values.
So! Consider Enumerable#associate
which builds a mapping by associating keys with values:
# Associate filenames with URLs. Before:
module DeleteResourceRoute | |
def resources(*args, &block) | |
super(*args) do | |
yield if block_given? | |
member do | |
get :delete | |
delete :delete, action: :destroy | |
end | |
end | |
end |
# | |
# Insert an automatic text MIME part into HTML e-mail. | |
# (c) Daniel Doubrovkine, Art.sy 2012 | |
# MIT License | |
# | |
class ActionMailerWithTextPart < ActionMailer::Base | |
def collect_responses_and_parts_order(headers) | |
responses, parts_order = super(headers) | |
html_part = responses.detect { |response| response[:content_type] == "text/html" } |
# From the project root | |
rvm env -- `rvm current` >> .powenv |