Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # let's say you have an Account model with first name and last name as its fields.
- #
- # I would put a method that returns both names like so:
- #
- class Account < ActiveRecord::Base
- def full_name
- "#{self.first_name} #{self.last_name}"
- end
- end
- #
- # Then, on the autocomplete line, add that method as the source of the text:
- #
- autocomplete :account, :first_name, :display_value => :full_name
- #
- # :first_name won't matter because you'll override it later
- #
- # Then, on your Controller, override get_autocomplete_items to:
- class SomeController < ApplicationController
- autocomplete :account, :first_name, :display_value => :full_name
- def get_autocomplete_items(parameters)
- Account.where("first_name LIKE ? OR last_name LIKE ?", "#{parameters[:term]}%").order(:first_name).order(:last_name)
- end
- end
Add Comment
Please, Sign In to add comment