Ruby on rails Problem

can some one tell me how to write this in ruby on rails active records objects form id

Payment.joins(:tenants).where(:payments {:name ‘sample’})

SELECT p.*, `tenants`.*, IF (IFNULL(p.`amount`,'0') = 0, 'Pay Now', 'Paid') AS amount2 FROM (
SELECT
    `payments`.`amount`
    , `payments`.`tenant_id`
FROM
    `payments` WHERE payments.`created_at` BETWEEN '#{Time.now.beginning_of_month}' and '#{Time.now.end_of_month}' ) AS p
    RIGHT JOIN `tenants`
        ON (p.`tenant_id` = `tenants`.`id`);