0

Assuming there is a community who has both "apple" and "APPLE" tags.

Then if I execute this with the param "apple"

@communities = Community.joins(taggings: :tag).where(tags: { name: params[:tag] })

In result page, 2 sets of the same community come appears.
It's probably because it's fetching with the params[:tag] for both upper case and lower case.

How can I strict this and make it not like search? I want case-sensitive and complete match.

0

1 Answer 1

4

Try enclosing attribute name in binary.

 @communities = Community.joins(taggings: :tag).where(['binary(tags.name) = ?', params[:tag]])
Sign up to request clarification or add additional context in comments.

9 Comments

Thanks!!! both of them didn't work. so I took the idea from your binary() then I did @communities = Community.joins(taggings: :tag).where('binary(tags.name)' => params[:tag]) but it still won't work:(
@communities = Community.joins(taggings: :tag).where('tags.name' => params[:tag]) This works but this fetches both "apple" and "APPLE"
I am not getting what is joins (taggings: :tag) means.. can you explain bit?
I'm using the gem called "acts_as_taggable". Usually this could be called easily by the dault method of this gem. just like this Community.tagged_with(params[:tag]) However it won't work for few tags somehow. I found out it's because of collation thing.
this gem automatically created 2 tables. but no model. tables are "Taggings" and "Tags". In taggings, it has "taggable_type, ""taggable_id", and "tag_id" this is polymorphic
|

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.