small medium large xlarge

11 Jan 2009, 07:19
Erik Petersen (7 posts)

So I followed along with episode 3, I knew most of it already and have been doing FormBuilders as plugins for a while (there is always something you don’t know). Anyway I’m having an issue with adding #labelled_form_for to ApplicationHelper.

Funny thing it works the first time to display the page but if you reload it raises:

` A copy of ApplicationHelper has been removed from the module tree but is still active!

/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:416:in load_missing_constant' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:77:in const_missing’ /Volumes/Data/cthree/Projects/coral/app/helpers/application_helper.rb:29:in `labelled_form_for’


Once I restart the server it will load the page again, once. This doesn’t happen if I do


<% form_for @foo, :builder => LabelledFormBuilder do f %>


and comment out the helper in ApplicationHelper.

That works everytime. It also works when wrapped in a plugin.

11 Jan 2009, 19:28
Bharat Ruparel (148 posts)

Hello Erik, I am on Rails 2.1.0. I have been running Episode 3 successfully for awhile with no problems. My form builder method is in Application Helper. Are you sure if there isn’t a typo or something? I have not worked with Rails 2.2 so it may be a Rails 2.2 issue? Anyway, I am looking at your error trace posted above and it says that you have an error in application_helper.rb in line 29. The code that I have in application_helper.rb extends to only 12 lines. Do you have extra stuff in that file? Bharat

11 Jan 2009, 21:15
Erik Petersen (7 posts)

Yes, I have other things in that file. There is no typo, and it may be an issue with 2.2.2. It has something to do with dependencies and loading and unloading of modules on the server with each request. Some things are loaded and unloaded with each request and some things are loaded only once (Application Helper is loaded only once which is why you need to restart the server when you change it). I suspect that is has to do with putting the builder module in app/form_builders and adding that to load_paths in environment.rb. As a plugin (loaded only once) it works fine and I suspect it would be fine if the form builder module were in lib/ since that is also only loaded once.

12 Jan 2009, 23:48
Ryan Bates (60 posts)

That’s an interesting problem. I don’t think it’s related to Rails 2.2.2 as I was using that in the episode. It sounds like there may be some other code influencing the loading of the ApplicationHelper module.

Unfortunately I’m unable to duplicate it on my end. See if the “pizzeria app code”: in episode 3 works for you. If it does then compare it to your code and see if you can find the problem.

05 Feb 2009, 21:46
Erik Petersen (7 posts)

Ok, I finally dug into this and found my problem deep in the test directory. Odd but true.

I had the following in test/mocks/development.rb:

require ‘controllers/application’ class ApplicationController < ActionController::Base def ssl_required? false end end

to stub out ssl in development mode. I guess I picked it up somewhere along the line, dropped it in there and never paid any heed. I was wondering why I was having to restart the server when making changes to helpers before they would register. I knew they were supposed to reload in development mode but when they didn’t I never bother to figure out why.

I deleted that file and now I can reload the form page over and over without problems. Sorry for the false alarm.

19 Apr 2009, 20:11
D4ddyK (1 post)


How did you manage to “dig around” to find your issue? I’ve got the exact same problem, except I’ve used Mike Mangino’s example from the Advanced Rails Recipes book. If I refer to the class explicitly in the form_for call, no problem. But if I refer to the method in ApplicationHelper, problem. I have no idea where to look.

27 May 2010, 12:50
Olivier Moratin (1 post)

I’ve had the same problem.

And it’s because I had a call to ActiveRecord in a custom method for my forms

class AppFormBuilder < ActionView::Helpers::FormBuilder
  # select_ethnicity
  def select_ethnicity(method = :ethnicity, options = {:include_blank => "All"}, html_options = {})
    collection_select method, Ethnicity.all, :id, 'name', options, html_options

If I remove Ethnicity.all it stops breaking

You must be logged in to comment