Parker
Parker

Reputation: 513

How much will this unconventional approach hurt my RoR application's performance?

This question is purely conceptual, it does not include any code.

I am building an app with a single User model. I would like to give users the freedom to choose from 3 different site styles. These styles will affect other components of the UX, including a Message model and messages controller.

I am thinking the best way to go about this is to give each user a "style" column, and based on which site style they choose, either save the value as a string or an integer into the users table.

I have concocted a way to use the same Message model and messages controller, and the same actions inside the messages controller, for all three of the different types of users. Within each of the actions of my messages controller, I would basically start off by querying for which "style" attribute the current user has in their corresponding database row. Based on the three possible "styles", I could then use an if-else or a switch statement to complete the right thing inside of the controller action, depending on the current user's style, including rendering a "style"-specific template rather than the default view template.

Is there a better way to go about accomplishing this? Is it completely discouraged altogether? Am I better off just creating 3 different messages controllers, would that be more RoR conventional and less damaging to the performance of the app?

How catastrophic would it be for the performance of my app if I were to follow this approach with the actions of my messages controller and maybe even two more controllers?

Thanks in advance for any insight anyone can give me :)

Upvotes: 0

Views: 55

Answers (1)

ConnorCMcKee
ConnorCMcKee

Reputation: 1645

I've done very similar things with little-to-no performance impact. As long as the changes are purely HTML/CSS/JavaScript this can be easily accomplished with a working knowledge of the Rails Asset Pipeline and a single column in the database. You'll end up hitting more if-statements in your views, but those handful of boolean expressions will have a negligible effect.

Just make very sure that your alternate view styles don't affect your Controller or the Models themselves (save any methods and validations pertaining to your new column in the User table).

Be sure to dish out unique scripts and stylesheets based upon which style the user has selected (it would be woefully inefficient to load a single stylesheet and dynamically change classes to use certain elements, for instance. Instead you'd want to choose which stylesheet to include based upon the user's selected style, and do the same for scripts).

If you have any specific questions about implementing this, feel free to inquire further. In the mean time this will prove to be an important read, if you are not already familiar with the material.

Upvotes: 1

Related Questions