0

I use rails 3.2.2 and autocomplete, I m selecting customer by name and formatting it in a following way
format.json { render :json => @customers.map{ |c| "#{c.name}:#{c.phone1}:#{c.email}" } }

so, i need to parse json properly an display in a way i want for example I want write name in but make font smaller and bold ,display it in different color. How i can achieve that?

<ul class="ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all" role="listbox" aria-activedescendant="ui-active-menuitem" style="z-index: 1; top: 416px; left: 0px; display: none; width: 419px;">
<li class="ui-menu-item" role="menuitem">
<a class="ui-corner-all" tabindex="-1">Adele Brekke:1-244-712-4421 x313:christophe@kuhlmanborer.net</a>
</li>
<li class="ui-menu-item" role="menuitem">
<a class="ui-corner-all" tabindex="-1">Madeline O'Conner Sr.:486-349-1046 x6765:kareem@hills.net</a>
</li>
</ul>
Cœur
  • 37,241
  • 25
  • 195
  • 267
alexeyb
  • 153
  • 2
  • 10

1 Answers1

0

may be this works for you,

format.json { render :json => @customers.map{ |c| "#{c.name}:<span style='font-size:smaller;color:red'>#{c.phone1}</span>:#{c.email}" } }
Hardik Patel
  • 838
  • 5
  • 12
  • where i should parsae it? I have Bryce Weber V:(555)800-2490 x7097:kyler@nienow.biz now in my list. – alexeyb Apr 02 '12 at 11:49
  • jQuery -> $('#product_customer_name').autocomplete source: $('#product_customer_name').data('autocomplete-source') this is my products.js.coffe – alexeyb Apr 02 '12 at 11:50
  • When i type its appear like text:

    'AAAAAAA'

    : :sa@gmail.com
    – alexeyb Apr 02 '12 at 12:06
  • yes, it is because when its render its convert HTML to STRING, you need to find a way to convert STRING to HTML at time of display on page using something like `html_safe` (http://stackoverflow.com/questions/4576932/ruby-on-rails-how-to-render-a-string-as-html) – Hardik Patel Apr 02 '12 at 12:11
  • I got it:) but where should i do it? Inside the coffee script or at the render stage? Thanks – alexeyb Apr 02 '12 at 12:43
  • I don't know whether you can able to add ruby code inside coffee script or not, I guess html_safe will work at the time of displaying data. – Hardik Patel Apr 03 '12 at 09:22
  • format.json { render :json => @customers.map{ |c| "

    '#{c.name}'

    : #{c.phone1}:#{c.email}".html_safe} } is not working for me in that way .
    – alexeyb Apr 04 '12 at 11:00
  • Its getting quite complected to achieve your goal, could you please share your javascript code? – Hardik Patel Apr 04 '12 at 11:42