Good practice for contracts?

Hi guys,

Probably something that many people had to do but that I can’t find any hints on internet!

Let’s say I have a model “Contract” that belongs to a “User”. The user has to accept the contract. Basically the “Contract” has few attributes, like “signature” that is an image and a “confirmed_at” date.

So far so good. Of course, there is a contract controller that render model attributes in JSON for my website, and also an HTML representation of this model.

The problem is that I want to show a “politic contract” from those informations. I want to show a long text with those informations that doesn’t necessarily belongs to user. Let’s say I only need “Contract” model to render that politic, but it’s not part of “Show” action in ContractController because it’s used to other calls AND I want other resources to render the politic contract.

Should I create another action to this controller by passing the contract ID as param? Should it be a completely new controller that its responsabilities is to render many type of contracts (because there are many)? Should I create a new “format” instead of HTML and JSON to use “respond_to”?

Because right now I have also long texts for “terms” and another one for “conditions” and was thinking of it was a good idea to group them.

Thanks

Hi, I’m new to rails so please bear with me. I was with you all up until “politic contract” as I don’t really get what you mean by that. But if you want a model with Contract as template I would just create another model called politic_contract with an STI to Contract. You can then assign the belong_to to “system” or whatever you want and then have another field like “from_user” to store which user you took the information from. You would manage this in the same ContractController as it’s just another Contract. This also allows you to have specific customization of the attributes whithin Contract. Of course, as I said, I’m completely new to rails and I might be entirely wrong. It’s just some food for discussion in case someone wants to expand on why my solution is a bad idea