Only thing not working as expected is that the h helper did escape html_safe output, but we can fix that easily…
Category Archives: Rails
Config files for heroku or duostack
To get config variables to herkou / duostack simply base64 encode them and store them into the ENV.
The cfg.rb is kept very simple, so you can also load it where rails is not yet loaded.
This scales to up to 3900 characters for duostack and 10000+ for heroku. Add gzip to get even more…
# lib/cfg.rb
require 'active_support/core_ext/hash/indifferent_access'
env = defined?(Rails.env) ? Rails.env : (ENV['RAILS_ENV'] || 'development')
config = if encoded = ENV['CONFIG_YML']
require 'base64'
Base64.decode64(encoded)
else
File.read('config/config.yml')
end
CFG = YAML.load(config)[env].with_indifferent_access.freeze
# config/application.rb
require File.expand_path('../../lib/cfg', __FILE__)
# script/configure_heroku.rb
#! /usr/bin/env ruby
require 'rubygems'
require 'rake'
require 'base64'
config = Base64.encode64(File.read('config/config.heroku.yml')).gsub("\n","")
sh "heroku config:add CONFIG_YML=#{config}"
Ruby Hash#contain?(other)
Check if one hash contains another.
Usage
params.contain?(:controller=>’home’, :action=>’index’)
Code
Fixing corrupt position in acts_as_list
When there is no uniqueness in mysql, things can go wrong….so we fix em…
Capistrano reuse tasks for deploy and quickfixes with current_release_or_path
- current_release only works in deployment
- current_path only works after deployment
- latest_release only works when all servers have the same timestamp for ‘latest release’
- current_release_or_path is always correct
def current_release_or_path exists?(:deploy_timestamped) ? current_release : current_path end