Printing field attributes outside the model.find_by_sql

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.

@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?

Todd A. Jacobs wrote in post #992052:

@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.

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.