Archives: 2009 June
Understand Named_scope in 60 seconds
June 28th, 2009, 1 Comment
Named scope was introduced in Rails 2.x, it allows you to filter a selection of records easily and repeatedly, without having to write finder SQL all the time.
class Customer < ActiveRecord::Base
has_many :carts
end
class Cart < ActiveRecord::Base
belongs_to :customer
named_scope :completed, :conditions => ["NOT ISNULL(completed_at)"]
end
Example of self-model scoping and finding:
# All completed carts [...]
Howto Display a GitHub Changelog in your application
June 27th, 2009, 2 Comments
In this post I will show you a simple way to display a list of your GitHub changes inside your application.
This can be useful for so many reasons, not least helping to create a better relationship between your users and your developers. This obviously would not be applicable in all circumstances, but in many cases, [...]
How to protect a folder by IP address in Nginx
June 20th, 2009, 1 Comment
To protect a folder by IP address in nginx is fairly simple, see the example below that demonstrates only allowing access to the /protected folder for people in the 192.168.0.* network.
server {
….
location /protected {
allow 192.168.0.0/24;
deny all;
}
…
}
Set your Rails Environment Globally
June 20th, 2009, Comments Off
In much of the rails documentation it is suggested that when you want to run a task in a specific environment, you should set the RAILS_ENV environment variable on the command line where you are running the task.
For example, assume you want to run rake db:migrate on the production system (should be done automatically [...]
Nudge Book and User-Website Interactions
June 18th, 2009, Comments Off
I have been reading the book Nudge: Improving Decisions About Health, Wealth and Happiness recently.
The book talks about how “choice architects” can make small changes to the way choices are presented (in every day life) and have a huge impact on the choices that people make.
What I found particularly interesting is how many [...]