سؤال

I have been playing around with this for a while, and it seems to querying my database, though no results are being shown. If someone can help with this would be great

View

= text_field_tag :postcode_tokens, params[:search], :placeholder => 'Multiple Suburb, Postcode, State or ID'

Model

attr_accessible :city, :pcode, :state, :postcode_tokens
attr_accessor :postcode_tokens

def postcode_tokens=(ids)
    self.postcode_ids = ids.split(',')
  end

Controller

def index
    @postcodes = Postcode.order('city ASC').where('city like ?', "#{params[:q].titleize}%").limit(5)
    render json: @postcodes
    #render json: @postcodes.map(&:city).uniq
  end

Coffee Script

 jQuery ->
  $('#postcode_tokens').tokenInput '/postcodes.json'
هل كانت مفيدة؟

المحلول

the json that tokenInput is waiting for must have these two attributes: 'id' and 'name'

so, you have two choices, either you modify your @postcodes elements to add these attributes to each one or you could change the attributes names used as key and value for elements in your coffeescript like this

$('#postcode_tokens').tokenInput '/postcodes.json', {
    tokenValue: "yourCustomId",
    propertyToSearch; "yourCustomName"
  }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top