I have been using RoR for the past two weeks, and I'm not sure where to put a piece of logic.
I have two models: Site
and Post
. The Post
model has many relationships with other models that represent all sort of metrics, for example: InteractionMetrics
. The interaction metrics are calculated as soon as a post is saved, and for the actual gathering of the data I use a third-party service. I've created an API wrapper (SDK) for the interaction with the third-party service, and in the InteractionMetrics
I have:
class InteractionMetrics < ApplicationRecord
def gather_interactions
client = XxxApi.new <url_of_post>
data = client.get_interactions
# Save data here
end
end
Now, I'm not sure if that's the correct place to put this logic, and if it's not, where should I put it instead?
Btw, I know I'm not supposed to ask more than one question, but I'm not sure how to get the post that this
belongs to.