मेरे पास एक एक्शनकेबल विधि है जो उपयोगकर्ता की सदस्यता लेती है। यदि कोई नया कॉन्वो शुरू हो गया है, तो मैं उपयोगकर्ता को नए चैनल में भी सब्सक्राइब करना चाहता हूं। मैं नियंत्रक में एक चैनल विधि को कॉल करने के लिए उचित वाक्यविन्यास नहीं समझ सकता।मैं रेल नियंत्रक में एक चैनल विधि कैसे कॉल कर सकता हूं?
अद्यतन: समस्या यह है कि संदेश भेजे जाने पर संदेशों को चैटबॉक्स में जोड़ा जाता है, लेकिन जब पहला संदेश भेजा जाता है, तो वेबसाईट कनेक्शन अभी तक स्थापित नहीं होता है, और इसलिए यह उपयोगकर्ता को लगता है जैसे संदेश नहीं था भेजा (क्योंकि यह संलग्न नहीं किया जा रहा है)।
चैनल/msgs_channel.rb
class MsgsChannel < ApplicationCable::Channel
#This function subscribes the user to all existing convos
def subscribed
@convos = Convo.where("sender_id = ? OR recipient_id = ?", current_user, current_user)
@convos.each do |convo|
stream_from "msg_channel_#{convo.id}"
end
end
#This is a new function I wrote to subscribe the user to a new convo that is started during their session.
def subscribe(convo_id)
stream_from "msg_channel_#{convo_id}"
end
end
मेरी convos नियंत्रक में, विधि बनाने के लिए, मैं कोशिश की है कई चीजें:
convos_controller.rb
def create
@convo = Convo.create!({sender_id: @sender_id, recipient_id: @recipient_id})
ActionCable.server.subscribe(@convo.id)
end
ActionCable.subscribe(@convo.id)
त्रुटि: NoMethodError (undefined method
सदस्यता ले 'ActionCable के लिए: मॉड्यूल) `
ActionCable.msgs.subscribe(@convo.id)
त्रुटि: NoMethodError (undefined method
msgs' ActionCable के लिए: मॉड्यूल):`
App.msgs.subscribe(@convo.id)
त्रुटि : NameError (uninitialized constant ConvosController::App):
MsgsChannel.subscribe(@convo.id)
त्रुटि: NoMethodError (undefined method
'MsgsChannel के लिए: Class`
ActionCable.server.subscribe(@convo.id)
त्रुटि: NoMethodError (undefined method
सदस्यता ले' सदस्यता लें # के लिए): `
आईडी पर आधारित प्रत्येक बातचीत के लिए वेबसाईट करने का प्रयास कर रहे हैं? –
@TallPaul यह सही है – gwalshington