How do I remove leading whitespace chars from Ruby HEREDOC?

后端 未结 11 687
误落风尘
误落风尘 2020-11-28 22:09

I\'m having a problem with a Ruby heredoc i\'m trying to make. It\'s returning the leading whitespace from each line even though i\'m including the - operator, which is supp

11条回答
  •  [愿得一人]
    2020-11-28 22:50

    I collect answers and got this:

    class Match < ActiveRecord::Base
      has_one :invitation
      scope :upcoming, -> do
        joins(:invitation)
        .where(<<-SQL_QUERY.strip_heredoc, Date.current, Date.current).order('invitations.date ASC')
          CASE WHEN invitations.autogenerated_for_round IS NULL THEN invitations.date >= ?
          ELSE (invitations.round_end_time >= ? AND match_plays.winner_id IS NULL) END
        SQL_QUERY
      end
    end
    

    It generates excellent SQL and do not go out of AR scopes.

提交回复
热议问题