I tried adding password and password_confirmation as text fields in my user dashboard so that they can be updated. Things seemed to work great! Then I tried searching, which blew up.
In the search class, it looks like the assumption is made that any searchable field type exists as a database column.
Perhaps it makes more sense for this to be configurable?
For example, my User dashboard could have
SEARCH_ATTRIBUTES = [
:email
]
and the search code might look like:
def search_attributes
attribute_types.keys.select do |attribute|
attribute_types[attribute].searchable? && search_attributes.include?(attribute)
end
end
def attribute_types
resolver.dashboard_class::ATTRIBUTE_TYPES
end
def search_attributes
resolver.dashboard_class::SEARCH_ATTRIBUTES
end
This may not be worth the trouble though if searching is going to be overhauled eventually.
You should be able to specify searchable in the with_options method in your dashboard class.
ATTRIBUTE_TYPES = {
name: Field::String.with_options(searchable: false),
}
Hi @thomascullen
It would be nice if it worked that way, but it seems to be hardcoded rather than based on options:
module Administrate
module Field
class String < Field::Base
def self.searchable?
true
end
# Truncated here for brevity
end
end
end
But I do agree that with_options feels like a better way to configure this rather than a new array of searchable fields as I initially suggested.
The with_options method creates a new instance of Deferred which allows searchable to be set with options in its searchable? method.
Is using with_options not working for you?
Oh my, I guess I didn't read the source closely enough. 馃槄 Ill give that a try and report back. Thanks!
Hah no worries! Glad to help :)
@andrewhamon Just wanted to check in on this. Were you able to get it working as @thomascullen suggested? If so, would you consider this issue resolved? Let me know, thanks!
Hey Carlos, it's been a year and I don't even remember what my use case was. I'm gonna assume that I got things working. Let's go ahead and close.
Okay @andrewhamon sounds good. Thanks for getting back to me!
Most helpful comment
You should be able to specify searchable in the
with_optionsmethod in your dashboard class.