나는 ROR에 아주 익숙하다. 나는 이것을 달성하는 데 어려움을 겪고있다.group_by on Rails
나는 다음과 같은 Working_hour 모델 및 상인 has_many의 working_hours 및 working_hour가 가맹점에 속한 가맹점 모델, 가지고 : 상인 두 working_hours을 가질 수
create_table "working_hours", force: :cascade do |t|
t.integer "day"
t.time "open_time"
t.time "close_time"
t.integer "merchant_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["merchant_id"], name: "index_working_hours_on_merchant_id"
end
class Merchant < ApplicationRecord
has_many :working_hours, inverse_of: :merchant, dependent: :destroy
accepts_nested_attributes_for :working_hours, reject_if: :all_blank, allow_destroy: true
end
근무 시간 테이블을 같은 날.
내보기 :
<% @merchant.working_hours.order(:day).each do |wh| %>
<li>
<%= t(:"date.abbr_day_names")[wh.day.to_i] %> :
<%= wh.open_time.to_formatted_s(:time) %> -
<%= wh.close_time.to_formatted_s(:time) %>
</li>
<% end %>
내가 검색 한 데이터가 하루 주문한보기에 표시됩니다 : I 그룹 일에 의해 working_hours 및이 방법을 표시 할 수있는 방법
Mon: 10:00-13:00
Mon: 17:00-20:00
Tue: 10:00-13:00
Tue: 17:00-21:00
Wed: 10:00-13:00
:
Mon: 10:00-13:00/17:00-20:00
Tue: 10:00-13:00/17:00-21:00
Wed: 10:00-13:00
레일 스케이프에서 group_by 튜토리얼을 봤지만 컨트롤러가 없습니다. working_hour 모델. 어떤 아이디어?
보기에 필요한 모든 데이터가있는 것처럼 보입니다. 당신은 그걸 제대로 조작 할 필요가 있습니다. 아마도보기에서 코드를 게시 할 수 있습니까? – phillyslick
내 질문을 편집했습니다. 그 벤을하는 것이 간단할까요? – user1301037