Skip to content


make the input method can accept a block #887

wants to merge 1 commit into from

2 participants


Sometimes I need to add something other into the input wrapper <li>, so it can be convenient if the input can be called with a block, and the block code is inserted after the input in the page .


Hi, thanks for the patch, but I'm nervous about accepting this right now without full consideration — it would effectively shut the door on what else we can use the block for.

My current approach is to define a custom input and incorporate the extra content there instead. Closing for now, sorry I don't have more time to go deep on this right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 21, 2012
  1. @zuozuo

    make input to accept a block

    zuozuo committed
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +4 −0 lib/formtastic/helpers/input_helper.rb
  3. +1 −1 lib/formtastic/inputs/base/wrapping.rb
1 .gitignore
@@ -15,3 +15,4 @@ Gemfile.lock
4 lib/formtastic/helpers/input_helper.rb
@@ -236,6 +236,10 @@ def input(method, options = {})
options = options.dup # Allow options to be shared without being tainted by Formtastic
options[:as] ||= default_input_type(method, options)
+ if block_given?
+ options[:block_content] = template.capture(&block)
+ end
klass = input_class(options[:as]), template, @object, @object_name, method, options).to_html
2 lib/formtastic/inputs/base/wrapping.rb
@@ -8,7 +8,7 @@ module Wrapping
# errors before the body of the input).
def input_wrapping(&block)
- [template.capture(&block), error_html, hint_html].join("\n").html_safe,
+ [template.capture(&block), options[:block_content], error_html, hint_html].join("\n").html_safe,
Something went wrong with that request. Please try again.