Turn `turbo_stream_actions` into a class method
Co-Authored-By: Georg Gadinger <nilsding@nilsding.org>
This commit is contained in:
parent
c3fa2701ba
commit
5a192a3598
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue