There was a question in the comments section of the AutoComplete Railscast that was unanswered and I need help with the same issue. http://railscasts.com/episodes/102-auto-complete-association-revised?view=comments#comment_159833
I'm implementing jQuery-UI Autocomplete with the datasource coming from a Rails Controller which in turn is calling the Foursquare API. The Foursquare API requires 2 parameters (a "query" and a "lat/long" value).
The Autocomplete widget's default param that it sends to the Rails controller is params[:term] which contains the "query". I need the Autocomplete Widget to pull the value from another text_field (let's call it the geocode_location field) and pass that as the "latlong" param.
So effectively, the GET request to the Rails Controller would be
Request URL:http://localhost:3000/foursquare?ll=37.7+-122.5&term=McDonalds
and not
Request URL: URL:http://localhost:3000/foursquare?term=McDonalds
Below is my current coffeescript file. I need to try to pass it extraParams or some way to let it know to pass a param named :latlong. How do I do that with Coffeescript and this type of data source?
$('[type="text"][name*="[location]"]').autocomplete
source: $('[type="text"][name*="[location]"]').data('autocomplete-source')
focus: (event, ui) ->
event.preventDefault()
$(this).val ui.item.label
select: (event, ui) ->
event.preventDefault()
$(this).val ui.item.label
$(this).siblings('[name*="[foursquare_id]"]').val ui.item.value
I'm not very familiar with Coffeescript syntax but really appreciate the help here. There is a similar question here but the data source for the autocomplete results is different. jQuery UI - Autocomplete with extra params - returned data