Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9061283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:26:40+00:00 2026-06-16T15:26:40+00:00

I’m experimenting with a few concepts (actually playing and learning by building a RoR

  • 0

I’m experimenting with a few concepts (actually playing and learning by building a RoR version of the 1978 database WHATSIT?).

It basically is a has_many :through structure with Subject -> Tags <- Value. I’ve tried to replicate a little of the command line structure by using a query text field to enter the commands. Basically things like: What's steve's phone.

Anyhow, with that interface most of the searches use ILIKE. I though about enhancing it by allowing OR conditions using some form of an array. Something like What's steve's [son,daugher]. I got it working by creating the ILIKE clause directly, but not with string replacement.

def bracket_to_ilike(arrel,name,bracket)
  bracket_array = bracket.match(/\[([^\]]+)\]/)[1].split(',')
  like_clause = bracket_array.map {|i| "#{name} ILiKE '#{i}' "}.join(" OR ")
  arrel.where(like_clause)
 end  

bracket_to_ilike(tags,'tags.name','[son,daughter]') produces the like clause tags.name ILiKE 'son' OR tags.name ILiKE 'daughter'

And it get the relations, but with all the talk about using the form ("tags.name ILiKE ? OR tags.name ? ",v1,v2,vN..)., I though I’d ask if anyone has any ideas on how to do that.

Creating variables on the fly is doable from what I’ve searched, but not in favor. I just wondered if anyone has tried creating a method that can add a where clause that has a variable number parameters.I tried sending the where clause to the relation, but it didn’t like that.

Steve

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:26:41+00:00Added an answer on June 16, 2026 at 3:26 pm

    Thanks to Phillip for pointing me in the right direction.

    • I didn’t know you could pass an array to a where clause – that opened up some options
    • I had used the splat operator a few times, but it didn’t hit me that it actually creates an object(variable)

    The [son,daughter] stuff was just a console exercise to see what I could do, but not sure what I was going to do with it. I ended up taking the model association and creating the array out of the picture and implemented OR searches.

    def array_to_ilike(col_name,keys)
      ilike = [keys.map {|i| "#{col_name} ILiKE ? "}.join(" OR "), *keys ]
      #ilike = [keys.size.times.map{"#{col_name} ILIKE ?"}.join(' OR '), *keys ]
      #both work, guess its just what you are use to.
    end  
    

    I then allowed a pipe(|) character in my subject,tag,values searches, so a WHATSIT style question

    • What's Steve's Phone Home|Work => displays home and work phone
    • steve phone home|work The ‘s stuff is just for show
    • steve son|daughter => displays children
    • phone james%|lori% => displays phone number for anyone who’s name starts with james or lori
    • james%|lori% => dumps all information on anyone who’s name starts with james or lori

    The query then parses the command and if it encounters a | in any of the words, it will do things like:

    t_ilike = array_to_ilike('tags.name',name.split("|"))
    # or I actually stored it off on the inital parse
    t_ilike = @tuple[:tag][:ilike] ||= ['tags.name ilike ?',tag]
    

    Again this is just a learning exercise in creating a non-CRUD class to deal with the parsing and searching.

    Steve

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.