Turn `turbo_stream_actions` into a class method

Co-Authored-By: Georg Gadinger <nilsding@nilsding.org>
This commit is contained in:
Andreas Nedbal 2023-02-11 14:41:36 +01:00 committed by Andreas Nedbal
parent c3fa2701ba
commit 5a192a3598
3 changed files with 10 additions and 12 deletions

View File

@ -1,11 +1,11 @@
# frozen_string_literal: true
class AnonymousBlockController < ApplicationController
include TurboStreamable
before_action :authenticate_user!
def turbo_stream_actions = %i[create destroy]
include TurboStreamable
turbo_stream_actions :create, :destroy
def create
params.require :question

View File

@ -3,18 +3,16 @@
module TurboStreamable
extend ActiveSupport::Concern
included do |controller|
around_action :handle_error, only: controller.respond_to?(:turbo_stream_actions) ? controller.turbo_stream_actions : []
class_methods do
def turbo_stream_actions(*actions)
around_action :handle_error, only: actions
end
end
def render_toast(message, success = true)
turbo_stream.append("toasts", partial: "shared/toast", locals: { message:, success: })
end
class_methods do
def render_toast = render_toast
end
private
def handle_error

View File

@ -1,11 +1,11 @@
# frozen_string_literal: true
class Settings::MutesController < ApplicationController
include TurboStreamable
before_action :authenticate_user!
def turbo_stream_actions = %i[create destroy]
include TurboStreamable
turbo_stream_actions :create, :destroy
def index
@users = current_user.muted_users