我知道如何工作has_many :posts, dependent: :destroy.如果帖子User或has_many帖子被销毁,所有所属帖子也会被销毁.
但Post模型会发生什么belongs_to :user, dependent: :destroy?我在Rails指南中找到了这个选项,但我找不到如何使用它.
我一直试图让我的头脑绕着动作电缆看似几个月.请帮忙.
我有一个"连接" - 我无法设置,identified_by :current_user因为此端点也需要由使用WebSockets的外部API使用.无法使用浏览器cookie来验证API端点.
连接: /app/channels/application_cable/connection.rb
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end
Run Code Online (Sandbox Code Playgroud)
渠道: /app/channels/application_cable/channel.rb
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
Run Code Online (Sandbox Code Playgroud)
我有一个特定的访问频道: /app/channels/visits_channel.rb
class VisitChannel < ApplicationCable::Channel
def subscribed
stream_from "visit_#{params[:visit_id]}"
end
end
Run Code Online (Sandbox Code Playgroud)
然后我有我的coffeescript频道: /app/assets/javascripts/channels/visit.coffee
App.visit = App.cable.subscriptions.create { channel: 'VisitChannel', visit_id: '42' },
connected: ->
# Called when the subscription is ready for use on the server
disconnected: ->
# Called when the subscription has been terminated by the server
received: (data) …Run Code Online (Sandbox Code Playgroud) ruby-on-rails channel coffeescript ruby-on-rails-5 actioncable