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