Rails observer callbacks in controller
I have observers set up on my r开发者_如何学运维ails app, that observer after_save(campaign).
Basically the observers look for specific tags in the campaign, and if those tags are present, it creates a new record in the "Achievement" model.
What I am trying to do is, in the campaign controller, see if any of these Achievements have been created by the observers, and if so, redirect the user to that Achievement show page.
I'm sure there is an easy function for this that I just don't know about...but what should I use?
Thanks in advance!
With no code, i'd assume the following:
Some kind of relationship between Campaign
and Achievement
Based on that you could do it with ruby like:
@campain = #however you find the campaign
if @campaign.include?(Achievement.find_by_tag(@tag))
redirect_to achievements_path
else
flash[:error] = "Not this time, dude."
#something here to redirect if NO achievement
end
精彩评论