Problem in retrieving data from MYSQL

Hi All,
I am writing a find_by_sql, as

EmailTemplate.find_by_sql(“SELECT subject FROM email_templates
WHERE
email_key=’#{template_key}’”)

The query is returning

‘— \n- !ruby/object:EmailTemplate \n attributes: \n subject:
“Text”\n’

as opposed to returning only “Text”.

Any clues?

Regards,
Mohit Ranka

EmailTemplate.find_by_email_key(template_key)

On Jan 31, 2008 4:26 PM, mohit_ranka [email protected] wrote:


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

mohit_ranka wrote:

Hi All,
I am writing a find_by_sql, as

EmailTemplate.find_by_sql(“SELECT subject FROM email_templates
WHERE
email_key=’#{template_key}’”)

The query is returning

‘— \n- !ruby/object:EmailTemplate \n attributes: \n subject:
“Text”\n’

as opposed to returning only “Text”.

Any clues?

Regards,
Mohit Ranka

that’s the wrong syntax…you should really use api.rubyonrails.org
search for find_by_sql in the bottom left frame and look at the syntax
but I’ll help you out:

EmailTemplate.find_by_sql([‘SELECT subject FROM email_templates WHERE
email_key=?’, template_key])

Unfortunately this is not my problem… My problem is to get
attribute value from the EmailTemplate object, that is being created.

On Jan 31, 12:47 pm, Phil T. [email protected]

mohit_ranka wrote:

Unfortunately this is not my problem… My problem is to get
attribute value from the EmailTemplate object, that is being created.

On Jan 31, 12:47 pm, Phil T. [email protected]

if i understand you then you should do this (thanks Ryan B.):

@subject = EmailTemplate.find_by_email_key(template_key)

then you can access subjects atrributes by doing:

@subject.[attribute_name]

does that help?

I have worked it out (finally)

EmailTemplate.find_by_sql(“SELECT subject FROM email_templates
WHERE
email_key=’#{template_key}’”).map(&:subject).to_s

This works fine. Thanks for your help :slight_smile:

Regards,
Mohit

On Jan 31, 2:39 pm, Phil T. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs