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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
EmailTemplate.find_by_email_key(template_key) On Jan 31, 2008 4:26 PM, mohit_ranka <mohitranka-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Rankathat''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]) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Tayo <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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]) > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Tayo <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>if i understand you then you should do this (thanks Ryan Bigg): @subject = EmailTemplate.find_by_email_key(template_key) then you can access subjects atrributes by doing: @subject.[attribute_name] does that help? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 :-)
Regards,
Mohit
On Jan 31, 2:39 pm, Phil Tayo
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> 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 Tayo
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
>
> if i understand you then you should do this (thanks Ryan Bigg):
>
> @subject = EmailTemplate.find_by_email_key(template_key)
>
> then you can access subjects atrributes by doing:
>
> @subject.[attribute_name]
>
> does that help?
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---