Oftentimes, I come across a situation that kind of irks me because I don't feel like my solution for it is up to par.
Say that I have a User model. There can be two TYPES of users - admins and the regular folk. In this particular case, I've simply split User and Admin into separate models - fair enough.
In some cases when there are numerous types of the same model (Foo
can be green, red, purple, yellow, etc)
I don't see much sense in dealing with 10 separate models like YellowFoo, GreenFoo, etc - so I add a "type" attribute to the model and then the code for, say, finding the correct object is simplified to User.where(:type => "some_type")
.
Is this an acceptable way of doing things in Ruby on Rails? Should the type be set to a be Symbol instead of a string so that User.where(:type => :some_type)
looks prettier or is this a hack no matter how you look at it?
Same goes for views that I create. In the above example, there is an admin controller with a whole separate dashboard from the users, even though the code for the dashboard is more or less the same, with a few exceptions (but in the future, potentially far more different). Is this an acceptable way of doing things or the newb way?
Thanks in advance!