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
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class AnonymousBlockController < ApplicationController
|
class AnonymousBlockController < ApplicationController
|
||||||
|
include TurboStreamable
|
||||||
|
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
|
|
||||||
def turbo_stream_actions = %i[create destroy]
|
turbo_stream_actions :create, :destroy
|
||||||
|
|
||||||
include TurboStreamable
|
|
||||||
|
|
||||||
def create
|
def create
|
||||||
params.require :question
|
params.require :question
|
||||||
|
|
|
@ -3,18 +3,16 @@
|
||||||
module TurboStreamable
|
module TurboStreamable
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do |controller|
|
class_methods do
|
||||||
around_action :handle_error, only: controller.respond_to?(:turbo_stream_actions) ? controller.turbo_stream_actions : []
|
def turbo_stream_actions(*actions)
|
||||||
|
around_action :handle_error, only: actions
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_toast(message, success = true)
|
def render_toast(message, success = true)
|
||||||
turbo_stream.append("toasts", partial: "shared/toast", locals: { message:, success: })
|
turbo_stream.append("toasts", partial: "shared/toast", locals: { message:, success: })
|
||||||
end
|
end
|
||||||
|
|
||||||
class_methods do
|
|
||||||
def render_toast = render_toast
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def handle_error
|
def handle_error
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Settings::MutesController < ApplicationController
|
class Settings::MutesController < ApplicationController
|
||||||
|
include TurboStreamable
|
||||||
|
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
|
|
||||||
def turbo_stream_actions = %i[create destroy]
|
turbo_stream_actions :create, :destroy
|
||||||
|
|
||||||
include TurboStreamable
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@users = current_user.muted_users
|
@users = current_user.muted_users
|
||||||
|
|
Loading…
Reference in New Issue