Remove newlines from strings in Rails
Rails has a method called squish
that will remove newlines from strings. It works very nicely with heredocs, where you may want readability but don't really want the newlines.
Without squish
:
<<~SQL
update posts
set status = 'public'
where status is null;
SQL
# "update posts\nset status = 'public'\nwhere status is null;\n"
With squish
:
<<~SQL.squish
update posts
set status = 'public'
where status is null;
SQL
# "update posts set status = 'public' where status is null;"
Tweet