Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 'to_sql' without '\'

So I just wanted to display

Shop.all.to_sql

as

 => "SELECT "shops".* FROM "shops"" 

but got

 => "SELECT \"shops\".* FROM \"shops\"" 

I tried gsub, but rails ignores '\'

Shop.all.to_sql.gsub('\', '')

How could I get rid of '\'?

like image 334
zombie_ghast Avatar asked Apr 11 '15 21:04

zombie_ghast


1 Answers

Those \ are not really there - this is way ruby displays strings (or rather this is the way inspect method works for strings). In short, it is to say that the next " is not the end of the string but rather a part of it:

'"'    #=> "\""

To see there are no slashes, tell ruby to display the resulting strings:

puts Shop.all.to_sql
# SELECT "shops".* FROM "shops"
#=> nil
like image 135
BroiSatse Avatar answered Oct 04 '22 12:10

BroiSatse