Reputation: 157
I have this code
def pull_group_info
# we want to store this section of information
@groupinfo = " name:\n
creditor_number,\n
iban,\n
company_invoices.from_date,\n
company_invoices.to_date,\n
rechnungsnummer,\n
company_invoices.r_number,\n
company_invoices.s_number:\n
companies.send_invoice_automatically:\n
companies.claim_netting:\n
company_invoices.total_cents:\n
rechnungsbetrag:\n
abrechnungsbetrag:\n
case_files.currency:\n
companies.vat_perspective:\n
companies.creditor_payout_by_case_file_invoice:"
end
def display_group_info
# we want to display information that we have pulled
@groupinfo
end
And now I would like to be able to display this info later, but with a quick call back in another function, what is the best way to go about this? Example below of what I've tried.
def query_for_****(_group_by, _companies_data)
''"
SELECT
distinct NAME,
puts @groupinfo
companies.data->>'creditor_number' as creditor_number,
companies.data -> 'pay_to_bank_account' ->> 'iban' AS iban,
Upvotes: 1
Views: 63
Reputation: 106782
I wouldn't recommend building SQL queries like this. But @groupinfo
is just a simple string and the query is a string too, which means you can just use string interpolation:
def query_for_****(_group_by, _companies_data)
"
SELECT
distinct NAME,
#{@groupinfo}
companies.data->>'creditor_number' as creditor_number,
companies.data -> 'pay_to_bank_account' ->> 'iban' AS iban,
But again, you tagged your question with ruby-on-rails
and you really should not build SQL statememts like that. I suggest reading in the Rails guides about the ActiveRecord query language.
Upvotes: 1