调用不同型号的多个项目?

发布于 2024-09-02 06:58:56 字数 770 浏览 0 评论 0原文

目前,在我的应用程序中,在 kase 模型中创建新的 kase 时,我可以从公司模型中选择一家公司。

<ul id="kases_new">
    <li>Company<span><%= f.select :company_id, Company.all.collect {|m| [m.companyname, m.id]} %></span></li>

这显示了公司列表,然后当我选择一个公司时,它会将公司 ID 添加到 kases 表中的 company_id 字段中。

我希望能够向 kase 添加第二家公司,但我不知道下一步是什么。我在 kases 表中创建了一个名为指定调查员 ID 的字段,因此当我选择公司时,它会将公司 ID 添加到指定调查员 ID 字段中。

这可行,但我需要能够像调用第一家公司一样调用有关该公司的信息。

<%= @kase.appointedsurveyor_id %>

上面返回的是company_id号,但是如何返回公司名称、地址等呢?

对于第一家公司来说很简单:

<li>Fax: <span><%=h @kase.company.companyfax %></span></li>

但如果我第二次这样做,我只会获得第一家公司的详细信息。

谢谢,

丹尼

At the moment in my application I can select a company from the company model when creating a new kase in the kase model.

<ul id="kases_new">
    <li>Company<span><%= f.select :company_id, Company.all.collect {|m| [m.companyname, m.id]} %></span></li>

This shows a list of the companies and then when I choose one it adds the company ID to the company_id field in the kases table.

I want to be able to add a second company to a kase but I don't know what the next step is. I have created a field in the kases table called appointedsurveyor_id so when I select the company it adds the company id to the appointedsurveyor_id field.

This works, but I need to be able to call information regarding that company like I would the first company.

<%= @kase.appointedsurveyor_id %>

The above returns the company_id number, but how do I return the company name, address and so on?

For the first company it is as simple as:

<li>Fax: <span><%=h @kase.company.companyfax %></span></li>

but if I do that a second time, I just get the first companies details.

Thanks,

Danny

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小耗子 2024-09-09 06:58:56

在您的 Kase 模型中:

belongs_to :surveyor,
           :class_name => "Company",
           :foreign_key => "appointedsurveyor_id"

然后您可以通过 @kase.surveyor 访问它,并可以访问所有 Company 信息。

In your Kase model:

belongs_to :surveyor,
           :class_name => "Company",
           :foreign_key => "appointedsurveyor_id"

Then you have access to it via @kase.surveyor and have access to all the Company info.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文