I am using rails3-jquery-autocomplete (version rails3-jquery-autocomplete (1.0.2)) in a Rails 3.0.10 application with Mongoid. A gem works like a charm, there is only one small question that I have. Would thank for any help in resolving it.
Basically I am trying to pass the autocomplete result identifier in the parameters. This is currently what I am doing.
In the controller:
class FeaturesController < ApplicationController autocomplete :feature, :name end
In view:
= autocomplete_field_tag :replacement_id, ' ', autocomplete_feature_name_features_path, :id_elements => '#replacement_id'
Route Files
resources :features do get :autocomplete_feature_name, :on => :collection end
Autofill is working fine. The only thing is that instead of passing the identifier of the auto-computer object (using: id_elements => '#replacement_id'), it passes the text.
This is what I get in the parameters:
Parameters: {"feature"=>{"status"=>"Replaced"}, "replacement_id"=>"Property agreements", "commit"=>"update_status"}
Currently, the value of "replacement_id" is "Property Agreement", which is an autocomplete text.
I was looking for related issues. I found that in the list of problems on Github there were similar problems in previous versions of gem here and. They have already been resolved, so there should be something wrong with my setup.
Thank you very much.
====== ====== UPDATE
oops! noticed a typo in the view helper! It should be: id_element instead of: id_elements. In mo, this does the trick, that is, it passes the identifier of the object to params:
eg. in parameters:
"replacement_id"=>"4e915ec88a812e2740000353"
However, it inserts the object identifier into the autocomplete text box instead of the autocomplete text. You can find a way around this.
====== UPDATE =========
In order to dispense with the possibility of displaying autocomplete text in a text field (it currently shows an identifier), I made the following changes:
View: I used the parameter: update_elements
= autocomplete_field_tag :replacement_id, '', autocomplete_feature_name_features_path, :update_elements => {:id => '#input#replacement_id', :name => 'input#replacement_id'}
Controller:
autocomplete :feature, :name, :display_value => :replacement_name, :extra_data => [:name]
: name is the method I put in the model:
def replacement_name "
Doing this displays the text in the autocomplete text box, but now the selected object identifier is not passed in the parameters, instead the text (as originally).