我有一份客户名单.每个客户都有一个链接,链接到客户页面并显示他的数据.
我想链接到客户表下方同一页面上的部分呈现.在使用表初始化"页面"时,应加载带有"选择客户"之类的空白页面.
我的客户列表代码:
<h1>Listing Customers</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th colspan="3">Actions</th>
</tr>
</thead>
<tbody>
<% @customers.each do |customer| %>
<tr>
<td><%= customer.name %></td>
<td><%= link_to 'Show', customer %></td>
<td><%= link_to 'Edit', edit_customer_path(customer) %></td>
<td><%= link_to 'Destroy', customer, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Customer', new_customer_path, class: "button", id: "new_customer" %>
Run Code Online (Sandbox Code Playgroud)
我部分用于展示客户:
<p>
<strong>Name:</strong>
<%= @customer.name %>
<%= @customer.id %>
</p>
<%= link_to 'Edit Customer', edit_customer_path(@customer) %> …Run Code Online (Sandbox Code Playgroud) 我在构建我.where以检索特定值时遇到了麻烦.
我有这个层次结构:
-顾客
--has_many项目
--- has_many门票
我想通过客户ID检索所有票证作为ActiveRecord :: Relation.
我的想法是这个循环(c是我想要门票的客户):
customer_projects = Project.where(:customer_id => c.id)
tickets = ActiveRecord::Relation.new(Ticket, anything)
customer_projects.each do |cp|
project_tickets = Ticket.where(:project_id => cp.id).where("DATE(created_at) >= ?", report.start_time).where("DATE(created_at) <= ?", report.end_time)
tickets.insert(project_tickets)
end
Run Code Online (Sandbox Code Playgroud)
我不知道在哪里写"任何"作为表参数,也不知道这是否有效.我更喜欢.where可以取回所有门票的"简单" .