searching two form at once

Hi,

I have a controllers called x and y. I want to search and display "y"
tables data using X's primary key, this key is a foreign key for Y.

eg-

when I click "show " option in the X table's index , I want to display
X's data and Y's data those are relavant to the X's primary key.( need
to display all in one form).

I would appreciate very much if any one can guide me or give me a link
to find the answer for this.

Many thanks.

Hi,

I have a controllers called x and y. I want to search and display "y"
tables data using X's primary key, this key is a foreign key for Y.

That does not make sense to me unless you mean that the id field in xs
table is the same as the id field in ys table. In that case why not
just combine the tables?

Probably I do not understand exactly what you mean. Is so please give
the relationships between the models (has_many, belongs to etc)

Colin

Hi Colin,

Thank you very much for your quick reply. I'm just sitting in front of
the computer and thinking what to do , because I'm new to ruby and
rails.

here is the explanation.

x has zero or more records in the y table. and y belongs to x.
hope this will help.x table id is name y table id is Itname. but both
are reprecenting the same data.

I appreciate if you can answer for this ASAP.

Thanks.

Colin Law wrote:

Hi Colin,

Thank you very much for your quick reply. I'm just sitting in front of
the computer and thinking what to do , because I'm new to ruby and
rails.

here is the explanation.

x has zero or more records in the y table. and y belongs to x.
hope this will help.x table id is name y table id is Itname. but both
are reprecenting the same data.

I think maybe you need get some basic rails knowledge. I suggest you
have a look at the rails guides at http://guides.rubyonrails.org/,
Start with Getting Started (obviously). To help with your problem
then look at ActiveRecord relationships. Then look through the
others. It is not that I do not want to answer your question
directly, but I think that you have some fundamental ideas wrong which
would be sorted by working through the guides.

Colin

Hi,

I didn't mean both controllers reprecenting the same data, I meaned X's
primary key is a foreing key in Y. need to seach both tables at onces
and display both tables record in a form.
Thanks.

Colin Law wrote:

Hi,

I didn't mean both controllers reprecenting the same data, I meaned X's
primary key is a foreing key in Y. need to seach both tables at onces
and display both tables record in a form.

Could you insert your comments after the relevant part of the mail you
are responding to please, it is easier to follow the thread then.
Thanks

I think we had better start again, show me the relationships you have
defined between your models, such as
x has many y, y belongs to x, or whatever it is, and what fields are
in the tables (just the important ones)

Colin

Colin Law wrote:

Hi,

I didn't mean both controllers reprecenting the same data, I meaned X's
primary key is a foreing key in Y. need to seach both tables at onces
and display both tables record in a form.

Could you insert your comments after the relevant part of the mail you
are responding to please, it is easier to follow the thread then.
Thanks

I think we had better start again, show me the relationships you have
defined between your models, such as
x has many y, y belongs to x, or whatever it is, and what fields are
in the tables (just the important ones)

Colin

Hi Colin,

Thanks for keeping in touch.
eg - order tabel- order id, desc, date, ....
     item table- itemno,name,price,oder id...

order id is common for both table, that is the link. One order has one
or more items.

want to show relevant item/s details (relevant to particular order)
when I click the show button in the order index form. I want to display
both order and relevant item/s data in one form.

Thanks.

Did you have a look at the guides I suggested? You do not appear to
be following the rails conventions. For example the order table
should not have a field called order_id, it should just be id. Also
the tables should be called orders and items, not order and item.
You have not told me the relationships (see the guide on ActiveRecord
relationships as I suggested). It is presumably something like order
has_many items and item belongs_to order. If you set this up
correctly then if you have an order in @order the items are
automatically available in the array @order.items. Please spend a few
of days working through some of the guides and trying examples from
the guides. It will be time well spent.

Colin