简体   繁体   中英

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

Got turbo-broadcasting from models work with mongoid. The steps were:

  1. use 'after_create' instead of 'after_create_commit' etc., since mongoid has different callbacks (you can check the full list here )
  2. 'include Turbo::Broadcastable' in your model

Hope this helps to someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM