Repository navigation
ruflet_rails: hand Action View-shaped text_field, textarea and checkbox calls back to Action View (form_with works again) - #120
Merged
Conversation
…rea and checkbox back to Action View The Railtie includes the HTML DSL helpers into every view, above Action View's FormHelper. text_field (and on Rails 8 textarea and checkbox) hid Action View's helpers of the same name, so form_with, form_for and fields_for builders raised ArgumentError on the host app's web pages. When the module is included, each DSL helper that hides a method of the including class (other than methods every object has) is wrapped: a call with more positional arguments than the DSL takes, or textarea with a Symbol second argument, goes to the hidden helper. Every other call runs the DSL helper unchanged. Fixes #116
This was referenced Nov 21, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #116
The Railtie includes the HTML DSL helpers into every view of the host app, above
ActionView::Helpers::FormHelper. The DSLtext_field, and on Rails 8textareaandcheckbox, hid Action View's helpers of the same name. As a result,form_with,form_forandfields_forbuilders (f.text_field,f.text_area,f.check_box,f.textarea,f.checkbox,f.collection_check_boxes) raisedArgumentErroron ordinary web pages, which returned HTTP 500.What changed
packages/ruflet_rails/lib/ruflet/rails/html_dsl/view_helpers.rb:Ruflet::Rails::HtmlDsl::ViewHelpersis included (self.included), each DSL helper that hides a method of the including class or module is wrapped. Methods every object has (Object.ancestors, such as ruflet_core's Kernel builders) do not count, because these helpers exist to replace them in views. Working this out at include time means:ActionView::Baseon Rails 8.1:text_field,textarea,checkbox; on Rails 7 onlytext_field);ActionView::Baseis never loaded early.super) when:text_fieldmore than 1,textareamore than 2,checkboxmore than 0). Every FormBuilder call passes object_name, method and an options Hash; ortextareawith a Symbol second argument (Rails 8'stextarea(:post, :body)). That Symbol names a model attribute, while the DSL's second argument is the text to show.bind_call) with the same arguments, so it renders byte-identical markup and raises the same errors.The README notes that Action View-shaped calls still reach Action View.
How verified
test/rails_form_helpers_test.rb, withtest/support/rails_form_helpers_app.rb, boots a real Rails app in its own process, asrails_executor_test.rbdoes.ruflet_railsis required beforeinitialize!, asBundler.requireloads it. The app is booted twice, once withruflet_railsand once without it (WITHOUT_RUFLET=1). Through real requests it renders 19 Rails cases:form_with,form_forandfields_forwith each field helper, options, custom checkbox values,collection_check_boxes, and directtext_field/textarea/checkbox/text_area/check_box. The test asserts that every case renders the same markup in both runs, and that 7 DSL calls in the same app's views render their 0.0.23 markup.test/html_dsl_hidden_helpers_test.rbuses stand-ins with Rails 8 and Rails 7 FormHelper signatures. It covers:textarea/checkbox, which hide nothing there;ArgumentErroras before;column,alert_dialog,input) are not wrapped.view_helpers.rb) makes both new files fail: 2 failures inrails_form_helpers_test.rb, and 1 failure plus 2 errors inhtml_dsl_hidden_helpers_test.rb. With the fix they pass. The DSL-markup tests pass both before and after, which shows that DSL output is unchanged.packages/ruflet_rails: each of the 21 test files run in its own process, 0 failures.bundle exec rake testgives 315 runs, 2969 assertions, 0 failures, 0 errors, 2 skips. The 2 skips are the existing SQLite executor scenarios, same as on main.cd packages/ruflet && ruby test/compat/compat.rb --jobs 4gives "checked 358 goldens", none failing.ruby -w. The wrapped method is removed before it is redefined.Tested on Ruby 4.0.5 / Rails 8.1.3.1. Rails 7 has no
FormBuilder#textarea, so the Rails 8-only cases are skipped there, and the Rails 7 shape is covered by the unit stand-ins.Behavior changes
Bug fix (D6): in Rails views, calls with Action View's FormHelper shape to a DSL helper of the same name now render Action View's markup:
ArgumentErrorbefore: everyf.text_field/f.text_area/f.textarea/f.check_box/f.checkbox/f.collection_check_boxesinform_with,form_forandfields_for, plus directtext_field(:post, :title, ...)and, on Rails 8,checkbox(:post, :published, ...).textarea(:post, :body, ...)(a Symbol second argument). It used to silently render the DSL tag<textarea name="post">body</textarea>and now renders Rails'<textarea name="post[body]" id="post_body">, which is what Rails 8 documents for that call. A DSLtextarea's second argument is the text to show, so a Symbol there was never meaningful DSL content.DSL calls within the DSL signature keep their path and byte-identical output. That covers every docs and test example:
text_field label: ...,text_field "x",textarea "bio", "Hi",textarea :bio, "Hi",checkbox name: .... Helpers that hide nothing are not touched, and nothing changes outside Rails views.