ruby on rails - after_create achievement notification from model -


i building achievement system , final part notifying user. once achievement created in model

class achievement < activerecord::base     def self.check_conditions_for(user)      if user.month_views >= 30 , !user.views_awarded?(self)       user.award(self)      end    end end 

i need flash custom notice user can close. best way initiate model? know can call flash messages controller need workaround in instance. similar how stack overflow displays badges.

ok if user views video -- presumably hitting url, should call achievement.check_conditions_for(user) in associated action. achievement.check_conditions_for(user) can return value - maybe notice message - can send normal flash message. no need workaround here if executed when action called.

for example, if have controller videos , you're calling action watch:

def watch   @video = video.find(params[:id])   @notice = achievement.check_conditions_for(current_user)   respond_to |format|     format.js   end end 

in app/views/videos/watch.js.erb:

alert("<%= @notice %>"); 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -