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

Raise helpful error when calling a missing rails helper #166

Merged
merged 3 commits into from
Mar 17, 2024
Merged
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
1 change: 1 addition & 0 deletions lib/phlex/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Rails

HTML.extend Phlex::Rails::HTML::Format
HTML.include Phlex::Rails::HTML::Format
HTML.include Phlex::Rails::HTML::MethodMissing

Unbuffered.prepend Phlex::Rails::UnbufferedOverrides
end
2 changes: 2 additions & 0 deletions lib/phlex/rails/html.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

module Phlex::Rails::HTML
autoload :MethodMissing, "phlex/rails/html/method_missing"

module Format
def format
:html
Expand Down
13 changes: 13 additions & 0 deletions lib/phlex/rails/html/method_missing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Phlex::Rails::HTML::MethodMissing
def method_missing(name, *args, **kwargs, &block)
return super unless helpers.respond_to?(name)

const_name = name.to_s.gsub("?", "")
module_name = Phlex::Rails::Helpers.constants.find { |mod| mod.to_s.underscore.gsub("domid", "dom_id") == const_name }
return super unless module_name

raise NoMethodError, "Try including `Phlex::Rails::Helpers::#{module_name}` in #{self.class.name}."
end
end