带有搜索和过滤器的 Ruby on Rails 表单查找

发布于 2024-12-06 23:17:54 字数 757 浏览 1 评论 0原文

基本上我有一个用户表和一个公司表。创建新用户后,他们会被分配到一个公司。我正在尝试找到一种方法,以便在创建新用户时,他们可以单击公司名称旁边的放大镜图标,然后会弹出一个较小的窗口,显示可用公司的列表。他们可以从此列表中对公司进行过滤和排序,然后单击其中一家公司即可填写新用户表单的这一部分。在 Ruby on Rails (v3.1.x) 中解决这个问题的最佳方法是什么

更新:为了寻找解决方案,我从一个下拉框开始。我暂时可以解决这个问题。但是,我确实想确保我可以在用户视图索引中引用此信息以显示公司名称而不是公司代码。

  <% label = content_tag("label", "Owner Company", :for => "companies_name") %>
  <% form_field = collection_select("user", "ownercode", Company.all, "companycode", "name") %>
  <%= content_tag(:div, "#{label} #{form_field}".html_safe,:class => "field") %>

在我的用户索引视图中,我有

<%= user.ownercode.company.name %>

来尝试显示该用户拥有的公司名称被分配到.当我编辑用户时,顶部部分现在可以工作。它将显示他们被分配到的公司的名称。然而,当显示用户索引、公司名称时,我的思绪开始滑落。

Basically I have a users table and a companies table. When a new user is created, they are assigned to a company. I am trying to find a way so that when a new user is created, they can click a magnifying glass icon next to the company name and it brings up a smaller window that shows a list of the available companies. From this list they are able to filter and sort the companies and click on one of them to have this part of the new user form filled out. What is the best way to approach this in Ruby on Rails (v3.1.x)

UPDATE: In efforts to find the solution, I've started with a drop down box. I can settle for this for now. However, I do want to make sure that I can reference back to this information in the User view index to display the company name instead of the company code.

  <% label = content_tag("label", "Owner Company", :for => "companies_name") %>
  <% form_field = collection_select("user", "ownercode", Company.all, "companycode", "name") %>
  <%= content_tag(:div, "#{label} #{form_field}".html_safe,:class => "field") %>

In my User index view i have

<td><%= user.ownercode.company.name %></td>

to try and display the name of the company that this user has been assigned to. The top part works now when I edit the user. It will show the name of the company that they are assigned to. However, my mind is slipping when showing the index of the users, the name of the company.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文