Reputation: 629
I have a model in my Rails app for a SalesOpportunity, and running a SWOT analysis (Strength, Weakness, Opportunity, Threat) to decide how good the SalesOpportunity is. Swots belong_to SalesOpportunities and therefore in the SalesOpportunity Model I have a method called update_swot_score which iterates through the Swot objects and calculates a score based on parameters I'm feeding in. All of this works fine.
What I'm wondering is whether I need to add a field to my SalesOpportunity model (let's call it swot_score for simplicity) and to update the instance variable at the end of the update_swot_score method using @swot_score = "results of my calculation", or whether I can directly access a result of the update_swot_score method (ideally in my view - I'll display different partials depending on the result).
What is the Rails way of doing this? Is there a performance efficiency to be gained by using either method?
Upvotes: 0
Views: 45
Reputation: 5112
i will suggest to add in the db
as a dedicated column to store score
...there are few good reasons as why you should do it:-
score
Model
cache
it..can also counter_cache
and expire
too.Hope it helps
Upvotes: 1