[1093] HABTM Select Filters #1928

Merged
merged 3 commits into from May 24, 2013

Conversation

Projects
None yet
2 participants
Owner

seanlinsley commented Feb 17, 2013

For #1093

  • Assuming Foo HABTM Bars, the below now works as you'd expect:
    ActiveAdmin.register Foo do
      filter :bars
    end
  • filter :attr, as: :select now utilizes ActiveRecord#pluck when using Rails >= 3.2 (resolves #2123)
  • polymorphic associations are now added to the default AA filters for a resource
Owner

seanlinsley commented May 4, 2013

This is now fully working. Thoughts @macfanatic?

lib/active_admin/filters/forms.rb
+ if method.present? && options[:as] ||= default_input_type(method)
+ form_buffers.last << input(method, options)
+ else
+ ''
@macfanatic

macfanatic May 6, 2013

Contributor

Why doesn't this empty string get appended to the form_buffers array?

@seanlinsley

seanlinsley May 6, 2013

Owner

I have no idea; that's just how the original code was implemented.

@seanlinsley

seanlinsley May 8, 2013

Owner

Ultimately what it's doing is calling our FormBuilder version of input:

def input(method, *args)
  content = with_new_form_buffer{ super }
  @inputs_with_block ? form_buffers.last << content : content
end

So the code in question should be simplified to be this instead:

def filter(method, options = {})
  if method.present? && options[:as] ||= default_input_type(method)
    input(method, options)
  end
end
Contributor

macfanatic commented May 6, 2013

@daxter - Other than my 1 question, looks good to me.

Owner

seanlinsley commented May 13, 2013

As it happens, 70d1df0 implements the things I described in #2123 💃

Owner

seanlinsley commented May 13, 2013

The logs on Travis are completely unreadable... Guess I'll have to build a Rails 3.0 test app and run everything locally.

seanlinsley added some commits May 6, 2013

fix HABTM select filters
Assuming Foo HABTM Bars, the below now works as you'd expect:
```ruby
ActiveAdmin.register Foo do
  filter :bars
end
```
better filter defaults
+ `filter :attr, as: :select` now plucks DB values by default
+ properly add default polymorphic filters
+ move common Formtastic overrides into a single module

seanlinsley added a commit that referenced this pull request May 24, 2013

@seanlinsley seanlinsley merged commit fe5becd into activeadmin:master May 24, 2013

1 check passed

default The Travis CI build passed
Details

@seanlinsley seanlinsley deleted the seanlinsley:1093-dropdown-for-habtm branch May 24, 2013

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