'Undefined method `after_create_commit' for Message:Class Did you mean? after_create - Rails action cable tutorial
I've tried to follow the ActionCable tutorial - Site point and I convert this tutorial to using MongoDB . But I have the problems with devise
NoMethodError in Devise::RegistrationsController#create
undefined method `after_create_commit' for Message:Class Did you mean? after_create
I don't have any ideas about this problems . Please help me , thank you so much.
message.rb
class Message
include Mongoid::Document
field :body, type: String
belongs_to :user
belongs_to :chat_room
validates :body, presence: true, length: {minimum: 2, maximum: 1000}
after_create_commit { MessageBroadcastJob.perform_later(self) }
def timestamp
created_at.strftime('%H:%M:%S %d %B %Y')
end
end
Solution 1:[1]
Got turbo-broadcasting from models work with mongoid. The steps were:
- use 'after_create' instead of 'after_create_commit' etc., since mongoid has different callbacks (you can check the full list here)
- 'include Turbo::Broadcastable' in your model
Hope this helps to someone.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | peresvetjke |