# \[n00b\] wildcard :select in find(:all) -\> malformed string

**URL:** <https://www.ruby-forum.com/t/n00b-wildcard-select-in-find-all-malformed-string/116163>\
**Category:** Rails\
**Created:** [October 3, 2007, 2:17am UTC](https://www.ruby-forum.com/t/n00b-wildcard-select-in-find-all-malformed-string/116163 "2007-10-03T02:17:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![olie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c4cdca/32.png) [@olie](https://www.ruby-forum.com/u/olie)\
**Post date:** [October 3, 2007, 2:17am UTC](https://www.ruby-forum.com/t/n00b-wildcard-select-in-find-all-malformed-string/116163/1 "2007-10-03T02:17:34Z")

</div>

I’m getting:

malformed format string - %’

When I do something like this:

```
$milestone = "(target_milestone LIKE '1.0 %' OR target_milestone

```

LIKE ‘TBD%’)"  
[…]  
@cond = $open\_bugs + " AND product like ‘" + $product\_name + "’"  
if $milestone.length \> 0  
@cond += " AND " + $milestone  
end  
[…]  
@pa\_bugs = Bug.find(:all,  
:conditions =\> [ @cond   
+ " AND priority = ‘" +  
@pri[“priority”] + "’"   
+ " AND assigned\_to = ‘" +  
@asn[“assigned\_to”].to\_s + "’"  
],  
:select =\> ‘bug\_id’  
)

If I take out the %, no malformed string but, also, wrong search  
conditions.

Can anyone explain what I’m seeing, why, and how to fix it?

Thanks!

P.S. I searched the archives for “wildcard” and saw a few posts, but  
none that spoke to this issue. Likewise, Googling

ruby rails select percent “malformed format string”

didn’t turn up anything helpful.

---

<div class="post-metadata">

**Author:** ![olie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c4cdca/32.png) [@olie](https://www.ruby-forum.com/u/olie)\
**Post date:** [October 3, 2007, 10:04am UTC](https://www.ruby-forum.com/t/n00b-wildcard-select-in-find-all-malformed-string/116163/2 "2007-10-03T10:04:53Z")

</div>

Who is throwing the error: the database or ruby? What is the actualy  
query that the database handles ?  
Also do you realise that you could do

@pa\_bugs = Bug.find(:all,  
:conditions =\> [ @cond + " AND priority = ? AND assigned\_to = ?",  
@pri[“priority”], @asn[“assigned\_to”]],  
:selec =\> ‘bug\_id’

Which is both more readable and not vulnerable to sql injection type  
errors.

Fred
