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 [...]
Archive for December, 2007
rescue_from
Posted in RubyOnRails on December 18, 2007 | Comments Off
RESTful routes (namespaced)
Posted in RubyOnRails on December 18, 2007 | Comments Off
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: [...]
rake db:migrate:redo
Posted in Quick Tips, RubyOnRails on December 18, 2007 | Comments Off
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
Rails 2.0.2
Posted in RubyOnRails on December 17, 2007 | Comments Off
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 [...]
Custom Rake tasks
Posted in Quick Tips, RubyOnRails on December 17, 2007 | Comments Off
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 [...]
backgrounDRb and RubyOnRails
Posted in RubyOnRails on December 14, 2007 | Comments Off
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 [...]
exists? == not_nil?
Posted in Ruby on December 12, 2007 | Comments Off
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.
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 [...]
Mikey
Posted in RSpec, Ruby, RubyOnRails on December 8, 2007 | Comments Off
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 [...]
Rails 2.0 released
Posted in RubyOnRails on December 7, 2007 | Comments Off
Well, it’s here. Rails 2.0 has been released.
Congrats to everyone on the team for a fantastic job.
