goddamnyouryan
goddamnyouryan

Reputation: 6906

Rails observer callbacks in controller

I have observers set up on my rails 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!

Upvotes: 1

Views: 1221

Answers (1)

pjammer
pjammer

Reputation: 9577

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

Upvotes: 1

Related Questions