1

過去数日間、レポの問題/PRを掘り下げて、リソースの属している関連をコレクション内でアルファベット順に並べる方法を考え出したので、助けが必要です。Rails5.0.7と Administrateを使用します0.10.0

私の状況では、Dish モデルと Restaurant モデルがあります。料理はレストランに属し、レストランには多くの料理があります。レストランの をクリックすると、レストランのではなく、レストラン<th>の に基づいて列が注文されることに気付きました。レストランの名前とアルファベット順に列を並べ替えるように変更したいと思います。以下の関連コード。idname

dish_dashboard.rb

class DishDashboard < Administrate::BaseDashboard
ATTRIBUTE_TYPES = {
    diets: Field::HasMany,
    restaurant: Field::BelongsTo.with_options(
      searchable: true,
      searchable_field: 'name'
    ),
    id: Field::Number,
    name: Field::String,
    description: Field::Text,
    picture: Administrate::Field::Image,
    price: Field::PriceField,
    price_currency: Field::String,
    deleted_at: Field::DateTime,
    published_at: Field::DateTime,
    created_at: Field::DateTime,
    featured: Field::Boolean
  }.freeze

  COLLECTION_ATTRIBUTES = [
    :name,
    :restaurant,
    :diets,
    :picture,
    :created_at,
    :featured,
  ].freeze
  ...
end

料理_collection.html.haml

%table.collection-data{"aria-labelledby" => "page-title"}
  %thead
    %tr
      - collection_presenter.attribute_types.each do |attr_name, attr_type|
        %th{class: "cell-label cell-label--#{attr_type.html_class} cell-label--#{collection_presenter.ordered_html_class(attr_name)}", scope: "col", role: "columnheader", :'aria-sort' => "#{sort_order(collection_presenter.ordered_html_class(attr_name))}"}
          = link_to(sanitized_order_params.merge(collection_presenter.order_params_for(attr_name))) do
            = attr_name.to_s.titleize
            - if collection_presenter.ordered_by?(attr_name)
              %span{class: "cell-label__sort-indicator cell-label__sort-indicator--#{collection_presenter.ordered_html_class(attr_name)}"}
                &#9660;
      %th{:class => "cell-label"} ACTIONS
  %tbody
    - resources.each do |resource|
      %tr.js-table-row{tabindex: 0, :'role' => 'link', data: {url: "#{polymorphic_path([namespace, resource])}"}}
        - collection_presenter.attributes_for(resource).each do |attribute|
          - next if attribute.html_class === 'boolean'
          %td{class: "cell-data cell-data--#{attribute.html_class}"}
            = link_to polymorphic_path([namespace, resource]), class: 'action-show' do
              = render_field attribute
        - if current_page?(admin_dishes_path)
          - if resource.featured?
            %td
              = button_tag '', class: 'btn toggle-actvation-btn unfeature-btn', type: 'button', data: { 'id': resource.id }
          - else
            %td
              = button_tag '', class: 'btn toggle-actvation-btn feature-btn', type: 'button', data: { 'id': resource.id }
          %td
            = button_to 'Delete', admin_dish_path(resource.id), method: 'delete', class: 'delete-btn'`enter code here`

今のところ、そのように見えます。コレクションのイメージ

注文オプションを使用してみましたが、ドキュメントによると、残念ながらテーブルではなくドロップダウンメニューのみです。名前に基づいて列をアルファベット順に並べ替える方法はありますか、それとも手動で行う必要がありますか?

4

0 に答える 0