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

Narrow down items with multiple colums #206

Open
soujiro0725 opened this issue Feb 3, 2013 · 4 comments
Open

Narrow down items with multiple colums #206

soujiro0725 opened this issue Feb 3, 2013 · 4 comments

Comments

@soujiro0725
Copy link

I have a model called Airport, which has three columns, name, city, and country.

I want autocomplete to narrow down the possible outcomes by typing name followed by city and country. How can I do that?

If my understanding is correct, I need to override the function

def get_autocomplete_items(parameters)
    super(parameters).where(:city => params[:city], :country => params[:country])
end

and add scopes

:scopes => [:city, :country]

in the form

<%= autocomplete_field_tag :departure_id, @departure_place,
autocomplete_airport_name_plans_path,
:size => 75, :scopes => [:city, :country], 'data-delimiter' => ' ' %>

But certainly it does not work. I am sure there must be a way.

@manusajith
Copy link
Member

@soichi777 currently autocompleting against multiple columns is not supported, but however there are some PRs addressing this issue.

@hlegius
Copy link

hlegius commented Nov 27, 2013

If you really, really need it - read again: really need it - there is a way:

In your autocompleted controller, overwrite autocomplete method:

def autocomplete_user_name
  items = User.find_by_full_name params[:term]
  extra_data = [:middle_name, :last_name]
  display_value = :full_name
  render json: json_for_autocomplete(items, display_value, extra_data)
end

This will work for any controller with: autocomplete :user, :name, full: true and User model with this method:

def full_name
  "#{name} #{middle_name} #{last_name}"
end

Anyway, @manusajith , there is a roadmap to continue this gem? I've already seen Rails 4 compatible fork; multiple rows fork and so on...

Thanks!

@manusajith
Copy link
Member

@hlegius the master branch currently supports rails4, we would be releasing a rails 4 compatible version of the gem soon.

@bigtunacan
Copy link
Contributor

We officially released a gem update with Rails 4 support in December. Work is still continuing on this gem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants