I used this video http://railscasts.com/episodes/102-auto-complete-association-revised to configure the form's autocomplete input for my application. (The video can only be for participants, so I will also publish my code. In fact, it looks for the DB column (name) and autocompletes in the drop-down list as it is input. This all works fine, but I would like form to do to represent an identifier that correlates with the name, not with the name itself.
I assume that there is no easy way to do this in a view only. Any help would be great. The code below let me know if any other code would be helpful.
thanks
Controller:
def game_name game.try(:name) end def game_name=(name) self.game = Game.find_by_name(name) if name.present? end
Coffee
jQuery -> $('#play_game_name').autocomplete source: $('#play_game_name').data('autocomplete-source')
In view:
<%= f.label :game_name, "Search for a game" %> <%= f.text_field :game_name, :class => "mlm mtm", data: {autocomplete_source: Game.order(:name).map(&:name)} %>
ruby jquery-ui ruby-on-rails activerecord ruby-on-rails-3
Clayton correia
source share