views:

36

answers:

3

Hello, I am building small app that will only display products in various categories. And will never display categories without products. So far I have two models - product and category and wondering if I really need controller dedicated to category model? I can only see one advantage so far - rendering collection (partial) of category. But it could be done via product as well. I want to keep the code as small as possible. Just wondering what is the best approach in such situation, what about routing and resources in rails 3? Thanks a lot for any suggestions.

A: 

don't you will need categories controller to add a new category or delete an unused one?

trying to "keep the code as small as possible" at earlier steps often makes your code messed-up at later development steps.

zed_0xff
Thans a lot I will add a controller.
bogumbiker
+1  A: 

I think you should keep the controller for the following reasons:

1) Maintenance of categories, basic CRUD functionality may need to be implemented so this will be required.

2) If anyone else has to maintain the code at a later date it is much easier for them if all the basic details are as expected. Finding a controller missing would probably start to raise a developers suspicions as to what other oddities there will later uncover.

3) How much smaller will not including the controller make it? Its not going to be a vast difference and so for clarity it is probably best to include it.

mfdoran
CRUD is the big deal here. How are you going to edit categories?
Scott Radcliff
Thanks a lot! I think now that you are right and will include controller. The idea was that 'category' will be read only. But after your comments I will definitely include controller for each model.
bogumbiker
A: 

Still in the same topic and CRUD.

It looks like I will not need CRUD for Category model. I am not going to display or manage it as it will be pure static data (still in db) but seeded only once. Therefore what benefit Category Controller would give?

In my app I will only display products inside category - will it be possible without having Controller for Category - I am thinking of valid URLs like /Category/1/Product/1 or even simplifying it to Product/1, Product/2 but still Category is used to navigate between categories.

Any advice or examples? Thanks

bogumbiker