The seven rules of a great git commit message
- Separate subject from body with a blank line
- Limit the subject line to 50 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line
- Wrap the body at 72 characters
- Use the body to explain what and why vs. how
Quick benchmark in IRB
if you want to see how quick/slow a command is in irb you can paste or mixin the following method:
def time(&block) puts Benchmark.measure(&block) end
then
time { something.that_takes_forever }
with thanks to: https://makandracards.com/makandra/20541-measure-code-execution-time-in-an-irb-or-rails-console
Rails LTS Rubygems server setup
If you'd like to switch to the Rubygems server, please see our installation instructions.
Rails LTS 3.2 setup
Rails 3.2 support is available to all subscribers on a Startup, Standard or Enterprise plan. To swap out the official Rails gems with Rails 3.2 LTS, please follow our installation instructions.
Fixing time inconsistencies in rspec
When comparing a date or time that has come from the database there may be slight differences that are not immediately noticeable. The spec will fail but the times in the output will look the same, this is due to microsecond differences.
One way around this (and please update this card if there is a better way) is to convert the time to an integer before doing the comparison i.e.
Timecop.freeze do
record = FactoryGirl.create...
Time.current.to_i.should == record.created_at.to_i
end
Old rspec syntax because i'm working on an o...
How To Set Up Multiple SSL Certificates on One IP with Apache on Ubuntu 12.04 | DigitalOcean
A guide for setting up SNI so that a single IP address can be used to have multiple SSL certificates serving the same or multiple sites.
Defining associated ids with FactoryGirl in a sane way
FactoryGirl.attributes_for doesn't honour associations defined in the factory so if you're submitting a user and you're sending along associated ids to create the associations it doesn't create the _id
attribute.
Here's a simple solution that can be used as a controller macro in your controller specs - usually where this rears its head.
module ControllerMacros
def attributes_with_foreign_keys(*args)
FactoryGirl.build(*args).attributes.delete_if do |k, v|
["id", "type", "created_at", "updated_at"].member?(k)
en...
Sprockets 2 with Rails 2.3 - Jared McFarland
A good article which explains how to add sprockets to Rails 2.3 to provide asset pipeline functionality.
I couldn't get the helper overrides to work as specified so simply directly referenced the absolute path to the assets, e.g. /assets/application.js
Bash: Batch rename files using the command line
Need to change the file extension for a bunch of files in your git repository? try:
find app/ -name '*.css.scss' -exec sh -c 'git mv "$0" "${0%.css.scss}.scss"' {} \;
This particular command finds all .css.scss files in the app folder and then iterates over them to rename them to .scss instead.
Rails: can't modify frozen Array
when upgrading from Rails 3.2 to 4.0 I encountered an issue trying to run the app:
/var/lib/gems/1.9.1/gems/actionpack-4.0.13/lib/action_dispatch/middleware/stack.rb:107:in `delete': can't modify frozen Array (RuntimeError)
from /var/lib/gems/1.9.1/gems/actionpack-4.0.13/lib/action_dispatch/middleware/stack.rb:107:in `delete'
from /var/lib/gems/1.9.1/gems/sass-rails-4.0.5/lib/sass/rails/railtie.rb:33:in `block in <class:Railtie>'
from /var/lib/gems/1.9.1/gems/activesupport-4.0.13/lib/active_support/lazy_load_hook...
Rails: uninitialized constant Draper::Base (NameError)
From Draper v1.0 your decorators need to inherit from Draper::Decorator
so:
class BookingDecorator < Draper::Decorator
instead of:
class BookingDecorator < Draper::Base
Rails: NoMethodError: undefined method `config' for nil:NilClass
While trying to upgrade from Rails 3.2 to 4.0 I had this problem when starting the app:
NoMethodError: undefined method `config' for nil:NilClass
/var/lib/gems/1.9.1/gems/railties-4.0.13/lib/rails.rb:32:in `configuration'
/var/lib/gems/1.9.1/gems/newrelic_rpm-3.4.1/lib/newrelic_rpm.rb:44:in `<top (required)>'
/var/lib/gems/1.9.1/gems/bundler-1.10.5/lib/bundler/runtime.rb:76:in `require'
/var/lib/gems/1.9.1/gems/bundler-1.10.5/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/var/lib/gems/1.9.1/gems/bundler-1.10.5/lib/bundler/r...
Rails: NameError: uninitialized constant Compass
While trying to upgrade an app from Rails 3.2 to 4.0, when trying to run the app I got the following error:
NameError: uninitialized constant Compass
/var/lib/gems/1.9.1/gems/fancy-buttons-1.1.2/lib/fancy-buttons.rb:1:in `<top (required)>'
/var/lib/gems/1.9.1/gems/bundler-1.10.5/lib/bundler/runtime.rb:76:in `require'
/var/lib/gems/1.9.1/gems/bundler-1.10.5/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/var/lib/gems/1.9.1/gems/bundler-1.10.5/lib/bundler/runtime.rb:72:in `each'
/var/lib/gems/1.9.1/gems/bundler-1.10.5/lib/bund...
Rails: LoadError: cannot load such file -- active_resource/railtie
Issue when upgrading from Rails 3.2 to Rails 4.0, having run bundle update rails ...
to update Rails and other gems with conflating gems, running bundle exec rake spec
throws the following error:
rake aborted!
LoadError: cannot load such file -- active_resource/railtie
/vagrant/config/application.rb:7:in `require'
/vagrant/config/application.rb:7:in `<top (required)>'
/vagrant/Rakefile:4:in `require'
/vagrant/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
Solution
ActiveResource is no longer a...
Installing Nokogiri 1.6.6.2 on Mac OS X 10.10
If nokogiri is failing to install
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2 --use-system-libraries
Configure bundler to use the same settings with
bundle config build.nokogiri --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2 --use-system-libraries
Find out when a keyword (method name, constant) is added or removed in git
When refactoring it is sometimes useful to see when a method or constant was introduced or removed.
git log -G'method_name'
git log -G'ConstantName'
If you see that a method is no longer used then you are safe to remove it. You can also see the context around why it was added which could make it easier to refactor.
How to upgrade a Rails 2.3 app to Ruby 1.9.3 - UserVoice Engineering
It may also be possible to upgrade higher according to this post:
CentOS 5 CA Certificate Bundle Update - Raymii.org
If you get errors such as error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed while accessing ...
and you're running an older version of CentOS, e.g. 5 or 5.5 then it's likely to be caused by the site certificate not being signed by one of the authorities in the default bundle.
You simply need to update the bundle as follows:
Back up old bundle
cp /etc/pki/tls/certs/ca-bundle.crt /etc/pki/tls/certs/ca-bundle.crt.bak
Copy bundle from cURL site
`wget -O /etc/pki/tls/certs/ca-bundle.crt http://curl.haxx.se...