Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1093] HABTM Select Filters #1928

Merged
merged 3 commits into from
May 24, 2013
Merged

[1093] HABTM Select Filters #1928

merged 3 commits into from
May 24, 2013

Conversation

seanlinsley
Copy link
Contributor

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 Better defaults for filters #2123)
  • polymorphic associations are now added to the default AA filters for a resource

@seanlinsley
Copy link
Contributor Author

This is now fully working. Thoughts @macfanatic?

if method.present? && options[:as] ||= default_input_type(method)
form_buffers.last << input(method, options)
else
''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@macfanatic
Copy link
Contributor

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

@seanlinsley
Copy link
Contributor Author

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

@seanlinsley
Copy link
Contributor Author

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

Assuming Foo HABTM Bars, the below now works as you'd expect:
```ruby
ActiveAdmin.register Foo do
  filter :bars
end
```
+ `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
@seanlinsley seanlinsley deleted the 1093-dropdown-for-habtm branch May 24, 2013 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better defaults for filters
2 participants