0

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'

1 Answer 1

2

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"
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.