Skip to content

Commit

Permalink
Warn when using options_for_select as a value
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper committed Dec 20, 2024
1 parent 4cd9cb3 commit 3066761
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
13 changes: 10 additions & 3 deletions lib/phlex/rails/helpers/options_for_select.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# frozen_string_literal: true

module Phlex::Rails::Helpers::OptionsForSelect
Never = Object.new

extend Phlex::Rails::HelperMacros

# @!method options_for_select(...)
# @return [nil]
register_output_helper :options_for_select
def options_for_select(...)
context = @_context
return if context.fragments && !context.in_target_fragment

raw helpers.options_for_select(...)

Never
end
end
21 changes: 18 additions & 3 deletions lib/phlex/rails/helpers/select_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
module Phlex::Rails::Helpers::SelectTag
extend Phlex::Rails::HelperMacros

# @!method select_tag(...)
# @return [nil]
register_output_helper :select_tag
def select_tag(*args, **kwargs, &block)
context = @_context
return if context.fragments && !context.in_target_fragment

if args[1] == Phlex::Rails::Helpers::OptionsForSelect::Never
raise ArgumentError.new(<<~MESSAGE
Figure out how to explain this problem here.
MESSAGE
end

output = if block
helpers.select_tag(*args, **kwargs) { capture(&block) }
else
helpers.select_tag(*args, **kwargs)
end

raw(output)
end
end

0 comments on commit 3066761

Please sign in to comment.