Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn when using options_for_select as a value #250

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading