class level methods are removed and created on each semantic_form_for call #904

the8472 opened this Issue Dec 18, 2012 · 4 comments


None yet

3 participants


semantic_form_for (and semantic_fields_for) does this:

@@builder.custom_namespace = options.delete(:namespace).to_s

custom_namespace is generated via class_attribute, which does does the following "fun" things:

  org/jruby/ `remove_method'
  activesupport (3.2.9) lib/active_support/core_ext/module/remove_method.rb:4:in `remove_possible_method'
  activesupport (3.2.9) lib/active_support/core_ext/class/attribute.rb:111:in `custom_namespace='
  org/jruby/ `module_eval'
  activesupport (3.2.9) lib/active_support/core_ext/class/attribute.rb:110:in `custom_namespace='
  formtastic (2.2.1) lib/formtastic/helpers/form_helper.rb:147:in `semantic_form_for'

it removes and generates several new methods every time semantic_form_for is called, this invalidates ruby's method caches and can lead to races under multithreading.

Easy to reproduce on the rails console the following way:

> Formtastic::FormBuilder.freeze
> helper.semantic_form_for :foo

@the8472 any suggestions on what changes to make? A pull request would be great!


We have to use a mutex if we want to keep the usage of class variable.

But I suggest to move that to an instance variable instead of a class variable, it's less problematic.


I don't know why it even is a class variable. If the namespace is only supposed to cascade to child form builders they could easily pass it down during construction. So yes, an instance variable would seem to be the cleanest solution.


@the8472 can you make a pull request changing it to instance variable?

@justinfrench justinfrench added this to the 3.0 final milestone Aug 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment