What's the convention in decoupling components in Rails
Using rails generate model, I created two models/tables, policeman and
policewoman. They are lists of officers with many attributes (age, time in
the field, case solved, etc.). If I wanted to do a computation that
determines who should get the next promotion to Sargent what is the
conventional way to do it in rails?
I would want to create a new class just to deal with this situation, and
hide all the complex computation (compare attributes between both lists)
away from the caller. So maybe in a controller, say Captain, under the
method show I would do
class Captain < ApplicationController
def show
promotion = Promotion.new
@ideal_sargent =
promotion.sargent(Policeman.find(:all),Policewoman.find(:all))
end
end
Where do I create this Promotion class? Do I use rails generate controller
to make it? Or maybe make a gem for it? Or even put it all in a model (I
hear thin controllers fat models)?
No comments:
Post a Comment