Last active
May 12, 2021 07:58
-
-
Save julianrubisch/509d94bf53e66cbcf376c40765e86e92 to your computer and use it in GitHub Desktop.
Allowlist Reflex Resources
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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