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
First shot at an automatic ransack implementation #36
Conversation
|
||
<%= render_if_exists "index_top" %> | ||
<%= render "list_filters" %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved some things around to make naming more consistent:
_index_top.html
is replaced by_index_header.html
and contains the resource name and "new resource" button (you can add eg. CSV buttons here without replacing_index.html
.) For backwards compatibility,_list_header.html
loads_index_top.html
- list filters are added below the header
class_eval <<-RUBY | ||
included do | ||
%w[list_fields filter_fields form_fields default_fields].each do |name| | ||
class_eval <<-RUBY, __FILE__, __LINE__ + 1 | ||
def self.#{name}(*fields) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did something like this recently, not sure if I like it better. Although this implementation is a bit cleaner, the interface is a bit less clear. I think here we'd want a nice DSL
class << self
attr_accessor :list_fields, :form_fields, :default_fields
end
@list_fields = [:title, :body]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain what the advantages or disadvantages are? I personally prefer the class method approach because it gives much better DSL then defining class instance methods. Imagine defining ActiveRecord relations like that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said, the DSL is a lot nicer as it is. I think the other implementation is a tad cleaner though, without class_eval
. But I think the nicer DSL is what counts here.
Conflicts: core/app/views/brightcontent/base/index.html.erb
First shot at an automatic ransack implementation
…lter-fields Allow arbitrary filter field names (fixes stefanroex#36)
I forgot what else I wanted to add before I went on vacation so I'll just post this now.
This PR adds the ransack gem and a
filter_fields
directive to Brightcontent controllers. By default, this gives you a dropdown with all the (unique) values in the database but you can also override this with a partial named_filter_field_*
as is customary.