I’m using jquery_token_input after following Ryan Bates railscast #258 and this is the code in the authors controller that searchs the entered query and produces json to render the autocomplete list.
Currently it selects the authors where the name is like the params entered.
Authors controller
def index
@authors = Author.where("name like ?", "%#{params[:q]}%")
respond_to do |format|
format.html
format.json { render :json => @authors.map(&:attributes) }
end
end
The author model has the columns :name and :user_id. I’d like to first select authors where the user_id is equal to the current_user.id. And then to select from that array the authors whos name is like the params entered.
Does this make sense? Any insight is greatly appreciated.
This ended up being the line I needed: (I have a helper method called uid)
Is there a way to improve this by removing the second where? Does that even matter?