Skip to content


Subversion checkout URL

You can clone with
Download ZIP


allow a proc to be given as label option #947

wants to merge 1 commit into from

4 participants


allow a proc to be given as label option, for example:

semantic_form_for(@new_post) do |builder|
  builder.input(:title, :label => proc{ 'My label' })

see details: #888


hmm, CI errors by:
Gem::InstallError: nokogiri requires Ruby version >= 1.9.2.
An error occurred while installing nokogiri (1.6.0), and Bundler cannot

how can I restart the CI jobs?


@rainchen we had the same issue in the rails4 branch, we need to lock nokogiri to < 1.6 until we drop 1.8.7. You can cherry-pick that commit, or wait 'till the #946 pull request is merged in (should be pretty soon).


@rainchen could you provide an example situation where you needed a proc?


@justinfrench please see details: #888
in short, I used it for i18n, like: builder.input(:title, :label => proc{ I18n.t(:xx) })


@rainchen Formtastic already has i18n support builtin for labels -- what functionality does this patch supply that isnt handled by the builtin functionality?


@twalpole some times you are not using the same key as the attribute for i18n, like builder.input(:title, :label => proc{ I18n.t(:title_with_special_notes) })


@rainchen but wouldnt
builder.input(:title, label: I18n.t(:title_with_special_notes))
do the same thing??


@twalpole but this is not working in ActiveAdmin, it's using some DSL methods like filter, the value of the label will be static if use filter :foo, :label => I18n.t(:foo).if you change the locale in url like /posts?locale=de, then the label won't be change to i18n with locale=de.All I have to do is using a proc like filter :foo, :label => proc { I18n.t(:foo) }.
anyway, allowing using a proc for label, will make formtastic more flexible.


imagine a situation where current_user has some impact on the label like:
:label => proc{current_user.admin? ? "hello" : "holla" }

So I agree with rainchen in this regard


I'm going to close this sorry. I've yet to hear of a concrete example in a real-world app that would need this (that couldn't be solved with standard i18n). I agree this would make Formtastic more powerful, but not in a direction I'm thrilled about. Ideally, we'd be removing all string options (e.g. :label) from the DSL and relying purely on I18n.

Happy to have this re-opened with a compelling real-world app case that I18n can't solve (and an up-to-date patch).

Thanks for your work so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 4, 2013
  1. @rainchen
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 0 deletions.
  1. +2 −0  lib/formtastic/localizer.rb
  2. +7 −0 spec/inputs/label_spec.rb
2  lib/formtastic/localizer.rb
@@ -61,6 +61,8 @@ def localize(key, value, type, options = {}) #:nodoc:
if value.is_a?(::String)
+ elsif value.is_a?(::Proc)# allow a proc to be given as label option
use_i18n = value.nil? ? i18n_lookups_by_default : (value != false)
use_cache = i18n_cache_lookups
7 spec/inputs/label_spec.rb
@@ -139,6 +139,13 @@
output_buffer.should have_tag('label b')
+ it 'should allow a proc to be given as label option' do
+ concat(semantic_form_for(@new_post) do |builder|
+ builder.input(:title, :label => proc{ 'My label' })
+ end)
+ output_buffer.should have_tag('label', /My label/)
+ end
Something went wrong with that request. Please try again.