undefined method generate_association_input_name #499

mhuggins opened this Issue Sep 20, 2011 · 16 comments


None yet
10 participants

Just installed ActiveAdmin for the first time on my Rails 3.1 app.

Everything worked fine until I attempted to access my first ActiveAdmin resource (generated via rails g active_admin:resource profile). It resulted in an error:

ActionView::Template::Error (undefined method `generate_association_input_name' for #<ActiveAdmin::FilterFormBuilder:0x000001059f9ba0>):
    1: render renderer_for(:index)

Rendered /Users/mhuggins/.rvm/gems/ruby-1.9.2-p180@dating/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.8ms)
Rendered /Users/mhuggins/.rvm/gems/ruby-1.9.2-p180@dating/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.3ms)
Rendered /Users/mhuggins/.rvm/gems/ruby-1.9.2-p180@dating/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (6.0ms)

ghost commented Sep 20, 2011

Got the same error message - mine due to using Formtastic 2.x, and not the Formtastic 1.x release

It seems to me the filter_select_input method in the ActiveAdmin FilterFormBuilder class calls method generate_association_input_name which is not there in the Formtastic 2.x release.

Quick "fix": comment out :filter declarations in your resource file (profiles.rb).

Other fix: force :filter declaration to be of another type than select i.e. :string:


filter :club_name, :as => :string, :label => 'Club' 

(assumes a resource that has a Club with an attribute name)

My profiles.rb is empty. I haven't included anything yet:

ActiveAdmin.register Profile do


I assume the reason for the error is still essentially the same in that it's auto-generating the columns and using :select as the filter type behind the scene.

zolk commented Sep 22, 2011

I'm having the same issue. Using Formtastic 2.0.0.rc5. All I've done so far is install ActiveAdmin and create an empty resource. No other changes made. The suggestion to force the filter to display as a string results in another error:

ActionView::Template::Error (undefined method `category_contains' for #<MetaSearch::Searches::Job:0x007feed79dd190>):
1: render renderer_for(:index)

Same problem for me with no :filter in my model.
My Gemfile.lock says formtastic (>= 1.1.0)
I get the problem only when I open the active admin page of my many to many join model "operation":

admin_users - operations - projects

The "project page" works fine in active_admin.

Yes, this appears to happen for any relationship that results in a checkbox or select input trying to be generated. Specifically, lines 108 and 117 of FilterFormHelper reference generate_association_input_name, which is no longer defined in versions 1.2.4+ of Formtastic.

Additionally, line 140 references a super method for find_collection_for_column, which is also no longer defined in Formtastic.

I haven't taken the time to fix it properly, but these issues can be fixed by doing the following:

  1. Create a local generate_association_input_name method that returns a string of the relationship's ID (e.g.: "profile_id" or "tag_ids"). Note that sometimes it returns the column name suffixed with _id for singular relationships, and other times returns the column name suffixed with _ids for plural relationships.

  2. Modify the find_collection_for_column to replace the call to super with the old Formtastic version of the method prior to it being deleted from the source tree. In other words, replace this:

    def find_collection_for_column(method, options = {})
      options = options.dup
      case options[:collection]
      when Proc
        options[:collection] = options[:collection].call
      super(method, options)

    with something like this:

    def find_collection_for_column(method, options = {})
      options = options.dup
      case options[:collection]
      when Proc
        options[:collection] = options[:collection].call
      collection = find_raw_collection_for_column(method, options)
      # Return if we have an Array of strings, fixnums or arrays
      return collection if (collection.instance_of?(Array) || collection.instance_of?(Range)) &&
                           [Array, Fixnum, String, Symbol].include?(collection.first.class) &&
      label, value = detect_label_and_value_method!(collection, options)
      collection.map { |o| [send_or_call(label, o), send_or_call(value, o)] }

There may be an easier/better way of doing these two steps that better conforms to Formtastic's internals, but I'm not familiar enough with them to know for sure.


bborn commented Sep 23, 2011

Getting this to with Formtastic 2.0 - switching back to 1.2.4 fixed for me.

Experiencing the exact same issues. I don't have a fix yet, going to try mhuggins's patch. Hope this issue gets some attention soon!

I too found the easiest (hopefully temporary) fix was to set my formtastic version specifically to "<= 1.2.4"

Unfortunately for me (and possibly other people here?), my project specifically required Formtastic 2.0, so ActiveAdmin won't work for me at all until this is officially fixed. I've got the workaround for now and will try to find time for an official fix this weekend unless someone beats me to it.


ebeigarts commented Sep 24, 2011

I have refactored the code to use Formtastic 2.0 with custom inputs, see #527

Going to go ahead and mark this issue as closed, assuming that #527 will remain opened until it's included.

@mhuggins mhuggins closed this Sep 26, 2011

elfassy commented Oct 3, 2011

+1 Same issue with simple_form

Weird, I seem to still be having this issue. I'm on activeadmin 0.3.1 and formtastic 2.0.2.


alzeih commented Nov 1, 2011

Also having issues with the same versions as brandonweiss

The case I have is:

filter :integer_field, :as => :select (and a :collection, but the :as => :select is enough to break it)

I have a form in the same file below the filter with the exact same input arguments and it works fine.


ebeigarts commented Nov 1, 2011

@brandonweiss, @alzeih: this is fixed only in master and it will be released only in v0.4.0


alzeih commented Nov 1, 2011

Thanks for your quick response - I can confirm this is fixed for me in the current master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment