I have two models in Rails, one is Worker and the other Assistance. A worker can have many assistances and each assistance is of a single worker.
I need to create a view where all the workers appear in each one and next to each worker I see the option to mark a boolean checkbox of the Assistance model, all in the same view and that when pressing save all the assistances of the workers are created at the same time.
What I have achieved is using nested resources and adding from the show view of each worker their attendance for that day, but I have not achieved what I asked previously. I do not know whether to create a new view, how to send the controller's data to the view, etc., I'm waiting for your help.
These are the corresponding models:
class Worker < ActiveRecord::Base
belongs_to :report
has_many :assistances, dependent: :destroy
belongs_to :equip
end
class Assistance < ActiveRecord::Base
belongs_to :worker
validates :fecha,uniqueness: { scope: [:worker_id] }
end
create_table "workers", force: :cascade do |t|
t.string "nombre"
t.integer "rut"
t.text "direccion"
t.string "telefono"
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "equip_id"
end
create_table "assistances", force: :cascade do |t|
t.integer "worker_id"
t.boolean "asistio"
t.boolean "excepcion"
t.date "fecha"
t.integer "horas"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end