class Comment < ApplicationRecord
belongs_to :post
belongs_to :author, class_name: 'User'
# Automatically broadcast changes to all subscribers of this post
after_create_commit -> { broadcast_append_to post, target: "comments" }
class DashboardWidget < ApplicationRecord
broadcasts_refreshes
end
class CommentsController < ApplicationController
before_action :set_post
def create
@comment = @post.comments.build(comment_params)
<%= turbo_frame_tag dom_id(flag) do %>
<tr class="flag-row">
<td class="flag-name"><%= flag.name %></td>
<td class="flag-env"><%= flag.environment %></td>
<td class="flag-state">
<span class="badge badge--<%= flag.enabled? ? 'on' : 'off' %>">
import * as Turbo from "@hotwired/turbo";
function metaContent(name) {
const el = document.querySelector(`meta[name="${name}"]`);
return el ? el.getAttribute("content") : null;
}
<h1>Create your account</h1>
<%= render "error_summary", record: @user %>
<%= form_with model: @user, url: signups_path do |f| %>
<div class="field">
<%= tag.div id: dom_id(comment), class: "comment", data: { controller: "comment" } do %>
<div class="comment__body">
<%= comment.body %>
</div>
<footer class="comment__meta">
<%= turbo_stream.prepend 'items' do %>
<%= render @item %>
<% end %>
<turbo-stream action="reset_form" target="new_item_form"></turbo-stream>
module TurboResponder
extend ActiveSupport::Concern
private
def respond_with_turbo(resource, on_success:, partial:, notice: nil)
<%= turbo_stream_from [current_member, :notifications] %>
<div id="notification_badge">
<%= render 'notifications/badge', count: current_member.notifications.unread.count %>
</div>
class CommentsController < ApplicationController
before_action :set_post
def create
@comment = @post.comments.build(comment_params)
import { StreamActions } from "@hotwired/turbo"
StreamActions.flash = function () {
const container = document.getElementById("flashes")
if (!container) return