开发者

Ruby on Rails Form Lookup with search and filters

开发者 https://www.devze.com 2023-04-08 15:28 出处:网络
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 n开发者_如何学Cew user is created, they can c

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 n开发者_如何学Cew 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消