Dinamyc callbacks on Rails, is it possible?

Today I have tried to do this: let any application application, and among all the tables to storage the data of your model estructure, there is one called «Configuration». As you can suspect, this table will storage some configuration options for your application. For some configuration options you need to execute certain code, and here is what I’ve tried:

class Configuration < ActiveRecord::Base
# These next lines are related to Hobo gem, and are just 
# an expression to define the model (you can imagine what they do for sure)
  fields do
    name :string
    value :string
    callback :boolean, default => false
    callback_name :string
end

after_update self.callback_name.to_sym, :if => self.callback?
... here comes the definition of each callback ...

For some reason this is not allowed. I think this is a nice solution to hook configuration options within code, but it doesn’t seem to work :/

If any of you get something like this working, please let me know, I will own a beer (no alcohol obviously 🙂

Cheers, Ibon.

Acerca de Ibon

Me gusta salir a correr, pasear, andar en bici y patinar :) Si no te saludo es que, o no llevo las gafas puestas o que tengo mal día. Pero no te lo tomes a mal: seguro que mañana estoy de mejor humor ;) Me gusta escuchar algunos podcasts sobre divulgación científica: Coffee Break, CienciaES, y algunos otros que divulgan buen karma. Creo en los principios que fundamentan el Software Libre, y me parece una gran herramienta para conseguir una sociedad mas justa.
Esta entrada fue publicada en Programación y etiquetada , , . Guarda el enlace permanente.

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.