Hi All, I have Model called pays..and it has fields like(id, topic, subject, created_at, b_id) and i also have a Model called suggests with fields(id, income, price, b_id) In my ruby on rails action or method Controller: def print_two_table @p = Pay.find_by_sql("SELECT p.id, p.topic, s.id, s.income, s.price FROM pays as P LEFT OUTER JOIN suggests AS s ON s.b_id = p.b_id WHERE p.created_at BETWEEN ''2008-03-04'' AND ''2008-07-06'' ") end In my View action or method: <%= @p.each do |form| %> <%= form.message %><br /> <%= form.income %><br /> (error on this part) <% end %> It gives me an error missing attribute What i want to accomplish is to be able to print field attributes in the suggests model or table. Any help is appreciated..TY. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Todd A. Jacobs
2011-Apr-11 02:55 UTC
Re: Printing field attributes outside the model.find_by_sql
On Apr 10, 7:42 pm, Ad Ber <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> @p = Pay.find_by_sql("SELECT p.id, p.topic, s.id, s.income, s.price FROM > pays as P LEFT OUTER JOIN suggests AS s ON s.b_id = p.b_id WHERE > p.created_at BETWEEN ''2008-03-04'' AND ''2008-07-06'' ") >[snip]> <%= form.message %><br /> > It gives me an error missing attributePerhaps because you aren''t selecting a message attribute in your SQL statement? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Todd A. Jacobs wrote in post #992052:> On Apr 10, 7:42pm, Ad Ber <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> @p = Pay.find_by_sql("SELECT p.id, p.topic, s.id, s.income, s.price FROM >> pays as P LEFT OUTER JOIN suggests AS s ON s.b_id = p.b_id WHERE >> p.created_at BETWEEN ''2008-03-04'' AND ''2008-07-06'' ") >> > [snip] >> <%= form.message %><br /> >> It gives me an error missing attribute > > Perhaps because you aren''t selecting a message attribute in your SQL > statement?Uhm..sorry that is an typo error.. what i means was In my View action or method: <%= @p.each do |form| %> <%= form.topic%><br /> <%= form.income %><br /> (error on this part) <% end %> Im having an error on the form.income part.. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bryan Crossland
2011-Apr-11 04:26 UTC
Re: Re: Printing field attributes outside the model.find_by_sql
On Sun, Apr 10, 2011 at 10:23 PM, Ad Ber <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Todd A. Jacobs wrote in post #992052: > > On Apr 10, 7:42pm, Ad Ber <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> @p = Pay.find_by_sql("SELECT p.id, p.topic, s.id, s.income, s.price > FROM > >> pays as P LEFT OUTER JOIN suggests AS s ON s.b_id = p.b_id WHERE > >> p.created_at BETWEEN ''2008-03-04'' AND ''2008-07-06'' ") > >> > > [snip] > >> <%= form.message %><br /> > >> It gives me an error missing attribute > > > > Perhaps because you aren''t selecting a message attribute in your SQL > > statement? > > > > Uhm..sorry that is an typo error.. > > what i means was > > In my View action or method: > > <%= @p.each do |form| %> > > <%= form.topic%><br /> > <%= form.income %><br /> (error on this part) > > <% end %> > > Im having an error on the form.income part.. > >If you have relationships setup between your models then getting to the income should be a easy as form.suggest.income or form.suggests.first.income depending on the relationship type. B. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ad Ber
2011-Apr-11 05:41 UTC
Re: Re: Printing field attributes outside the model.find_by_sql
Uhm..TY..I have configured the model relationships...I was ABLE to display form.income as long as i include the FIELD IN THE QUERY... My follow up question is what if i want to display a specific field in my VIEW but they have the same FIELD name..For example, th id in the PAYMENTS table and the id in the SUGGESTS table have the same field name... I want to be able to display the correct the PAYMENTS id and correct SUGGESTS id.. My Database is big im having a hard time to trace..which id it belongs to. Please help me. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.