Sql Script Doubt

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

hey thanks

hey thanks

> 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