rails初心者です。
多対多のビューを作ることになり、中間テーブルを用意したものの、どのようにビューに表示すれば良いのかわからず途方に暮れています。お力を貸していただけると嬉しいです。
目標:下のようなテーブル形式のチェックボックスをform_forで作ること
曜日/時間 月曜 火曜 水曜 木曜 金曜 土曜 日曜
午前 ☑️ ☑️ ☑️ ...
お昼
午後
夜
用意したもの
1.teacher.rb
ruby
1class Teacher < ApplicationRecord 2 # Include default devise modules. Others available are: 3 # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable 4 devise :database_authenticatable, :registerable, 5 :recoverable, :rememberable, :validatable 6 7 has_many :teacher_week_times 8 has_many :hours, through: :teacher_week_hours 9 has_many :weeks, through: :teacher_week_hours
2.week.rb
class Week < ApplicationRecord has_many :teacher_week_hours has_many :teachers, through: :teacher_week_hours has_many :hours, through: :teacher_week_hours end
3.hour.rb
class Hour < ApplicationRecord has_many :teacher_week_hours has_many :teachers, through: :teacher_week_hours has_many :weeks, through: :techer_week_hours end
4.teacher_week_hour.rb
class TeacherWeekHour < ApplicationRecord belongs_to :teacher belongs_to :week belongs_to :hour end
テーブルとカラムの関係
teachers idカラム
weeks monday,tuesday,wednesday,thursday,friday,saturday,sundayカラム
hours hour1,hour2,hour3,hour4カラム
中間テーブルを作る時点で既に間違っている箇所や、form_forで目標のようなビューを作るのに足りないことがあれば教えてくださると嬉しいです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。