Skip to content

Instantly share code, notes, and snippets.

@julianrubisch
Last active May 12, 2021 07:58
Show Gist options
  • Save julianrubisch/509d94bf53e66cbcf376c40765e86e92 to your computer and use it in GitHub Desktop.
Save julianrubisch/509d94bf53e66cbcf376c40765e86e92 to your computer and use it in GitHub Desktop.
Allowlist Reflex Resources
module Submittable
extend ActiveSupport::Concern
include StimulusReflex::ConcernEnhancer
included do
prepend_before_reflex do
instance_variable_set("@#{resource_name.underscore}", resource_class.new(submit_params))
end
end
private
RESOURCE_ALLOWLIST = {
"boards#show" => "Embed",
"embeds#show" => "Comment"
}.freeze
def resource_name
RESOURCE_ALLOWLIST["#{request.parameters["controller"]}##{request.parameters["action"]}"]
end
def resource_class
resource_name.safe_constantize
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment