Hello everyone,

I am having a doubt regarding sql in rails .. i kept the autocomplete
feature in my application .. but the problem is there should not be
repitition in the term in the text field... This is what i done ....


class SkillsController < ApplicationController

def index
term = (params[:term].split(",").last || "").strip

@skills = Skill.order(:name).where('name LIKE?', "%#{term}%")

render :json => @skills.map(&:name)
end

Can anyone please help.... ASAP

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Walter Lee Davis at Oct 3, 2012 at 12:56 pm

    On Oct 3, 2012, at 6:33 AM, BalaRaju Vankala wrote:

    Hello everyone,

    I am having a doubt regarding sql in rails .. i kept the autocomplete feature in my application .. but the problem is there should not be repitition in the term in the text field... This is what i done ....


    class SkillsController < ApplicationController

    def index
    term = (params[:term].split(",").last || "").strip

    @skills = Skill.order(:name).where('name LIKE?', "%#{term}%")

    render :json => @skills.map(&:name)
    end

    Can anyone please help.... ASAP
    I'm usually against answering ASAP questions, but have you tried adding .uniq at the end of your @skills query?

    Walter

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • BalaRaju Vankala at Oct 3, 2012 at 1:52 pm
    hey thanks
    On Wed, Oct 3, 2012 at 6:26 PM, Walter Lee Davis wrote:

    On Oct 3, 2012, at 6:33 AM, BalaRaju Vankala wrote:

    Hello everyone,

    I am having a doubt regarding sql in rails .. i kept the autocomplete
    feature in my application .. but the problem is there should not be
    repitition in the term in the text field... This is what i done ....

    class SkillsController < ApplicationController

    def index
    term = (params[:term].split(",").last || "").strip

    @skills = Skill.order(:name).where('name LIKE?', "%#{term}%")

    render :json => @skills.map(&:name)
    end

    Can anyone please help.... ASAP
    I'm usually against answering ASAP questions, but have you tried adding
    .uniq at the end of your @skills query?

    Walter

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    నేను
    కొంచం తపన,
    కాస్త ఆసక్తి,
    కొన్ని కలలు,
    కాసిన్ని ఊహలు కలిపేస్తే
    నేను
    bala raju

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Walter Lee Davis at Oct 3, 2012 at 1:57 pm

    On Oct 3, 2012, at 9:45 AM, BalaRaju Vankala wrote:

    hey thanks

    On Wed, Oct 3, 2012 at 6:26 PM, Walter Lee Davis wrote:
    On Oct 3, 2012, at 6:33 AM, BalaRaju Vankala wrote:

    Hello everyone,

    I am having a doubt regarding sql in rails .. i kept the autocomplete feature in my application .. but the problem is there should not be repitition in the term in the text field... This is what i done ....


    class SkillsController < ApplicationController

    def index
    term = (params[:term].split(",").last || "").strip

    @skills = Skill.order(:name).where('name LIKE?', "%#{term}%")

    render :json => @skills.map(&:name)
    end

    Can anyone please help.... ASAP
    I'm usually against answering ASAP questions, but have you tried adding .uniq at the end of your @skills query?
    Glad it helped, but doesn't this solution point back to a problem with your model? If Skills are a separate model, why are their names allowed to be duplicates? Names should be enforced at the model level to be globally unique, that way a result in this picker will point unequivocally to a single object. After all, you do want the results for a search to include all the different skills that include the substring from the progressive search -- that's how this should work.

    Walter
    Walter

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.





    --
    నేను
    కొంచం తపన,
    కాస్త ఆసక్తి,
    కొన్ని కలలు,
    కాసిన్ని ఊహలు కలిపేస్తే
    నేను
    bala raju

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedOct 3, '12 at 10:33a
activeOct 3, '12 at 1:57p
posts4
users2
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase