Buenas Tardes. Soy nuevo en Ruby On Rails, y me encuentro desarrollando una aplicación en la cual los docentes de un colegio pueden realizar reportes de los alumnos, con restricción de acceso con login y usuario (utilizando devise), los docentes pueden crear estudiantes y realizar los reportes de cada estudiante. Tengo creados los siguientes modelos:
student: para los alumnos class Student < ActiveRecord::Base validates :documento, :colegio, :nombres, :apellidos, :tipodocumento, :genero, :fechanacimiento, :edad, :etnia, :depto, :ciudad, :localidad, :barrio, :grado, :jornada, :discapacidad, :dirresidencia, :telcontacto, :nombreacudiente, :nombremadre, :nombrepadre, presence: true has_many :events end event: para los reportes class Event < ActiveRecord::Base belongs_to :student belongs_to :officer has_many :comments end officer: para los docentes class Officer < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable has_many :events include PermissionsConcern end Siguiendo un tutorial realice esta migración: class AddOfficerIdToEvents < ActiveRecord::Migration def change add_reference :events, :officer, index: true add_foreign_key :events, :officers end end En el contralador events_controller, puedo crear el reporte del alumno. dclass EventsController < ApplicationController before_action :authenticate_officer! def create @student = Student.find(params[:student_id]) @event = @student.events.create(event_params) redirect_to student_path(@student) end private def event_params params.require(:event).permit(:fechareporte, :fechaevento, :lugar, :tipoagresion, :atencionmedica, :conoceagresor, :relacionagresor, :generoagresor, :lesiones, :descripcion, :officer_id) end end Pero quiero poder almacenar al mismo tiempo el officer_id, del usuario logueado, para luego poder mostrar el correo del docente que realizo el reporte. Se que esta linea: @event = @student.events.create(event_params) Se crea y guarda el reporte, ademas asocia automáticamente el alumno. Pero no se como modificarla para que también almacene el officer_id del docente que realiza el reporte. Ayuda...! Por favor Agradezco inmensamente su ayuda. Gracias -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/910f8bd1-1562-4cea-87df-1ab8ba1d42c1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.