0

我有简单的预订和客户模型:

class Client
  include DataMapper::Resource
  property :id, Serial
  property :name, String, required: true
  property :email, String, required: true
  #....
  has n, :bookings, constraint: :destroy
end

class Booking  
  include DataMapper::Resource  
  property :id, Serial
  property :start_date, Date
  property :end_date, Date
  #....
  belongs_to :client
end

在视图中按预期生成了一个表:

<% @bookings.each do |booking| %>
  <tr>
    <td><%= booking.client.name %></td>
    <td><%= booking.start_date %></td>
    <td><%= booking.end_date %></td>
    ....
  </tr>
<% end %>

我想通过单击相应的表格列标题来订购表格。

我可以让表格按 :start_date 或 :end_date 排序,也可以按 :client_id 排序,但 :client_id 不是很有用;我希望能够通过 :client_id 的 Client 模型的 :name 属性进行排序

有人可以告诉我我的控制器需要采用什么格式吗?

get '/bookings' do
  @bookings = Booking.all(order: :client_id.name) #no method error
  @bookings = Booking.all(order: [:client_id][:name]) #can't convert to integer
  erb :bookings
end

谢谢

4

0 回答 0