Feeds:
Posts
Comments

Archive for December, 2007

rescue_from

It is very common for me to have some rules regarding who can access data on the sites I build. For this example we have clients that have products. Users belong_to a client and therefore only have access to that client’s product. A user should not be able to access a [...]

Read Full Post »

RESTful routes (namespaced)

I like having my administration (management) controllers namespaced. From a security perspective, it’s easier to exclude a group of admin functions from certain users (or the general public) if you namespace the routes.
map.namespace(:admin) do |admin| admin.resources :users end

#The above will look for a controller class named: [...]

Read Full Post »

rake db:migrate:redo

Nice new rake command to rollback one migration and migrate back up. If you need to go further than one step back pass the STEP=x parameter.
#Roll back 3 migrations and migrate back to current version.rake db:migrate:redo STEP=3

Read Full Post »

Rails 2.0.2

The team didn’t waste much time. A new release is out with some bug fixes and two major changes:1) SQLite3 is the new default database. Use rails -d mysql newapp, to generate a mysql database.yml template.2) Rails no longer checks for template changes in production mode.
Read more…
Apparently it hasn’t propagated across all servers [...]

Read Full Post »

Custom Rake tasks

Writing your own custom Rake task is very simple and almost not worthy of a blog post, but I can’t remember everything, so it’s here for reference.
In your lib/tasks directory create a file with the extension .rake. i.e. print.rake.

namespace :print do
task :one do
attention “One”
end

task [...]

Read Full Post »

backgrounDRb and RubyOnRails

Lately I’ve been running into the situation where I need to have a process running to periodically handle some task like sending emails or other bulk processing. Well, if you run into that situation I highly recommend using a very nice plugin by Ezra called backgrounDRb.
BackgrounDRb is ruby server that allows [...]

Read Full Post »

exists? == not_nil?

Apparently Facets adds the exists? functionality in the form of not_nil?. It seems there’s a lot of goodness in Facets that I will now have to investigate. Thanks to Trans for giving me the heads up.
Here’s to not re-inventing the wheel. Cheers.

Read Full Post »

exists?

I like readable code is it’s one of the nice attributes of Ruby. Today I had some code that could use some improvement.
Ruby has a method called nil? that you can send to any object. When I want to test is that object is not nil? I could:
#use unless unless [...]

Read Full Post »

Mikey

So, I have a site that synchronizes data with another server. It does this via after_create, after_update and after_delete triggers on some models. All of those triggers use the same method that returns a connection object which has various methods such as:
# SyncServer::connection method module SyncServer def [...]

Read Full Post »

Rails 2.0 released

Well, it’s here. Rails 2.0 has been released.
Congrats to everyone on the team for a fantastic job.

Read Full Post »

Older Posts »