0

I am trying to autocomplete a search, the only issues is i am fetching two information. I am following the tutorial here http://railscasts.com/episodes/102-auto-complete-association-revised

Here the issues

  def index
    @titles = Event.order(:title).where("title like ?", "%#{params[:term]}%")
    @customers = Customer.order(:first_name).where("first_name like ?", "%#{params[:term]}%")
    render json: @titles.map(&:title)
    render json: @customers.map(&:title)
  end

If both contain something how can i return both objects.

1 Answer 1

1

You have to create a single JSON object which contains both information, like this:

respond_to do |format|
  format.json { render json: {titles: @titles.map(&:title), customers: @customers.map(&:title)} }
end

Haven't tested it, but it should work.

Sign up to request clarification or add additional context in comments.

2 Comments

Failed to load resource: the server responded with a status of 500 (Internal Server Error)
Please post the whole error in your question. And maybe also your routes.rb and your controller for your autocomplete search.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.