Caching: don't use content_for, it won't work
Do not use content_for
inside a cached view fragment. It won't work because Memcache will just output whatever is in the cache, and not execute such commands.
Related cards:
Database: Scopes, migrations, and indices
Wether you modify an existing named scope or add a new one, or when you write a new query, make sure you have the proper indices.
This particularly applies if you're going to run non-trivial queries of course (admin backends, analytics, etc).
##...
Rebase your feature branches
Regularly, but at least before merging your feature branches, rebase them to get rid of "fix typo" and "wip" commits.
Getting rid of unnecessary commits
Let's say you do a git rebase -i HEAD~~~~
and have this...
How to run long scripts on production/staging server
In a nutshell, use screen
Why?
Sometimes we are concerned that if our connection gets closed, the process we are running will close too.
The processes or login sessions you establish through screen don't go away. You can resume your...
When you set date attributes, you should not pass times
As you know, time zones make stuff a bit more difficult but are necessary.
A time-zoned record is converted to UTC using to_s(:db)
to be st...
Respect time zones: Use Time.current and Time.zone.parse
Reading the current time
Don't use Time.now
as it's broken when using time zones. \
Instead, use Time.current
, DateTime.current
or Date.current
...
Keeping your specs DRY
I often see long before
blocks with lots of should_receive ... and_return
inside.
Remember that before
blocks are about setting up the "stage" (the context of your test), not declaring your expectations!
Also, they get run for every spec (e...
Creating a gem in lib folder
Go to lib folder and use bundler to generate main files for a gem:
$ bundle gem test_gem
create test_gem/Gemfile
create test_gem/Rakefile
create test_gem/LICENSE
create test_gem/README.md
...
DateTimes are Dates, beware
Given:
datetime = DateTime.now
date = datetime.to_date #or Date.today
will assert:
datetime.is_a? Date == true
datetime.is_a? DateTime == true
datetime.instance_of? Date == false
datetime.instance_of? DateTime == true
In case y...
jQuery ajax success/done will not run callbacks if request is json but the response is empty (typical 200)
When using
var onDone = function() { ... }
var onFail = function() { ... }
var params = { ... }
var url = ...
$.ajax({
type: 'put',
url: url,
contentType: 'application/json; charset=utf-8',
data: JS...
Method return value should always be of same type
One of the main source of bugs and complexity in the code is when a functional method (that we expect to return a value) return different values under different circumstances.
For example, we ruby programmers have a bad habit of returning nil fro...