Hi all,
I’m building my first Rails app and looking for some advice about how
to architect my controllers. I’m essentially building a sales tracker.
Sellers log in and post their sales; buyers log in and see a list of
their purchases. Admins can do everything sellers and buyers can do.
So far I’ve built out the admin controller. It now has most of the
app’s functionality, and in the process I’ve gotten comfortable with
Rails. Now, I’m ready to build the more specific app functionality
which will allow sellers and buyers to log in and interact with the
data from their different perspectives. Here’s where I hit an
architecture question and would love some advice.
My question: Should i create separate controllers for both buyers and
sellers? Initially I thought yes, since the options available to these
two sets of users will be different. But now I’m realizing that they
will also share quite a bit of code with each other and with the admin
controller. For example, “view sale details” is the same whether it’s
in a buyer context, a seller context, or an admin context.
How best should I architect my app to keep DRY? Should I make the
buyer and seller controllers children of the admin controller, thus
inheriting its methods? Somehow this doesn’t seem quite right. Is
there some other way to reuse code across multiple controllers? Or
maybe these shouldn’t be separate controllers after all?
Thanks in advance and please let me know if you need more specific
info to be able to offer advice.
Cheers,
Jacob