Skip to content

Commit

Permalink
Raise helpful error when calling a missing rails helper
Browse files Browse the repository at this point in the history
Co-Authored-By: Seth Horsley <[email protected]>
  • Loading branch information
joeldrapper and SethHorsley committed Mar 17, 2024
1 parent 16e7ce5 commit 8ba1a69
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
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
9 changes: 9 additions & 0 deletions lib/phlex/rails/html/method_missing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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 your class."
end
end

0 comments on commit 8ba1a69

Please sign in to comment.