0

For my new project, I need a functionality like mail filters. There will be a set of rules with associated actions. When an user submits a request, it needs to be passed through these rules for validation. In case any one of these rules matches, the corresponding action should be triggered (or, the model should be updated with a few more attributes). Just like mail filters.

And, these rules will be user specific and stored as ActiveRecord models.

Any pointers for existing gems?!

My ROR version is 2.3.8

Shan
  • 1

1 Answers1

0

You're looking for validation at the controller level. What I would recommend is to add filters in your ApplicationController.

For example :

class ApplicationController < ActionController::Base
    before_filter :is_logged_in
    def is_logged_in
        # ... do your stuff !
    end
end

What is great with this is :

  • you can with ruby, as a OO language, create you own hierachy of classes, thus making your code easyly understandable, dry an all.
  • having before filter, after filter ... look here for more infos http://guides.rubyonrails.org/action_controller_overview.html
  • access the current controller and action : controller.controller_name and controller.action_name

Also, keep in mind that there are validation you should implement at the model level. ActiveRecord also provides a set of useful similar filters : http://guides.rubyonrails.org/active_record_validations_callbacks.html#available-callbacks

Marcel Falliere
  • 1,884
  • 21
  • 39
  • Marcel, Guess I was not clear in the original post. What I am looking for goes beyond validation. It is more like business rules. In a CRM application, if the request is from a particular company or for a particular product or based on timezone etc., assign to this group, set it to high priority etc., – Shan Dec 07 '10 at 12:49
  • Yes Marcel! But not a full blown workflow system like Stonepath or something similar. Just simple rules check like mail filters. If a rule matches, do the corresponding action and exit. Otherwise go to the next rule. At the outset, it may sound like a workflow engine, but far simpler. – Shan Dec 08 '10 at 07:24
  • OK Shan, maybe you sould look around http://ruby-toolbox.com/categories/state_machines.html. – Marcel Falliere Dec 08 '10 at 07:48
  • Thanks Marcel. I have skimmed through ruby-toolbox earlier, will check it on again. – Shan Dec 08 '10 at 12:01