I try to use observers in a rails application to create a new entry in my "Events" model every time a new "comment" is saved. Comments are saved well, but the observer does not create events properly.
// comment_observer.rb class CommentObserver < ActiveRecord::Observer observe :comment def after_save(comment) event = comment.user.events.create event.kind = "comment" event.data = { "comment_message" => "#{comment.message}" } event.save! end
This observer works fine, I use it in the console, but it does not seem to be observed properly; when I try to use the application, it just does not generate events. I see no errors or anything else.
I also have config.active_record.observers = :comment_observer in the environment.rb file.
Where am I mistaken? Should I take a different approach?
source share