当我创建笔记时,为什么user_id在这里获得NIL

时间:2018-02-12 03:35:51

标签: ruby-on-rails

这是我的约会控制人。在这里,为什么user_id在这里获得NIL?虽然我已经拥有了user_id。 关联:约会has_many Notes,用户has_many Notes,Notes belongs_to User,Notes belongs_to Appointment

def new
    @appointment = Appointment.new
    @note = @appointment.notes.build({user_id: current_user.id})
end

def create
    @appointment = Appointment.new(appointments_params)
    @appointment.patient_id = current_user.id

    if @appointment.save
      flash[:notice] = "Appointment saved!"
      redirect_to authenticated_root_path
    else
      render 'new'
    end
  end

private
def appointments_params
  params.require(:appointment).permit(:date, :doctor_id, :patient_id, :image, :starting_time, notes_attributes: [:id, :description, :user_id, :_destroy])
end

0 个答案:

没有答案
相关问题