gpt4 book ai didi

ruby-on-rails - 我在更新对象后收到一条 "patient successfully updated"消息,但 Rails 中的值保持不变?

转载 作者:太空宇宙 更新时间:2023-11-03 18:01:25 25 4
gpt4 key购买 nike

抱歉,我真的不知道如何更好地表达这个问题,但这是我的问题:

当我尝试在我的 Rails 应用程序中更新或创建一个患者对象时,值没有被发送到模型,因为当我尝试创建一个新患者时,我收到验证错误,我不得不输入值(我这样做了),当我更新现有患者对象时,即使我收到“成功更新患者”的消息,值也不会改变

知道为什么会这样吗?

它过去工作正常,但我没有更改患者 Controller 或模型中的任何内容以使其停止工作?

如果您需要我的任何代码,请告诉我您需要什么。

Controller 创建和更新代码:

class PatientsController < ApplicationController

before_filter :require_user
load_and_authorize_resource

def new
@patient = Patient.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @patient }
end
end

def edit
@patient = Patient.find(params[:id])
end

def create
@patient = Patient.new(params[:patient])
respond_to do |format|
if @patient.save
format.html { redirect_to(@patient, :notice => 'Patient was successfully created.') }
else
format.html { render :action => "new" }
end
end
end

def update
@patient = Patient.find(params[:id])
respond_to do |format|
if @patient.update_attributes(params[:patient])
format.html { redirect_to(@patient, :notice => 'Patient was successfully updated.') }
else
format.html { render :action => "edit" }
end
end
end

end

服务器日志:

  Parameters: {"commit"=>"Update", "authenticity_token"=>"7ypFp3DhLokjvqau06+EOOoEU2T/7UmU5OaAZuGxC1M=", "id"=>"4", "patient"=>{"occupation"=>"nothing", "blood_type"=>"O+", "next_of_kin"=>"mo man", "address"=>"arcklow", "m_name"=>"gfjhgjgfj", "date_of_first_admission(1i)"=>"2006", "tel_number"=>"45345435", "weight"=>"85.0", "date_of_first_admission(2i)"=>"3", "f_name"=>"Allan ", "date_of_first_admission(3i)"=>"3", "mobile_number"=>"43534543", "universal_ID"=>"bebo", "sex"=>"Female", "medical_history"=>"Wrist is", "height"=>"187.0", "family_history"=>"", "bmi"=>"15", "allergies"=>"", "date_of_birth(1i)"=>"1986", "date_of_birth(2i)"=>"8", "email"=>"allandx@gmail.com", "current_medication"=>"ibrufen", "date_of_birth(3i)"=>"17", "l_name"=>"Dixon"}}WARNING: Can't mass-assign these protected attributes: occupation, blood_type, next_of_kin, address, m_name, date_of_first_admission(1i), tel_number, weight, date_of_first_admission(2i), f_name, date_of_first_admission(3i), mobile_number, universal_ID, sex, medical_history, height, family_history, bmi, allergies, date_of_birth(1i), date_of_birth(2i), email, current_medication, date_of_birth(3i), l_name  [4;35;1mPatient Load (0.1ms)[0m   [0mSELECT "patients".id FROM "patients" WHERE ("patients"."email" = 'allandx@gmail.com' AND "patients".id  4) LIMIT 1[0m  [4;36;1mPatient Load (0.1ms)[0m   [0;1mSELECT "patients".id FROM "patients" WHERE ("patients"."universal_ID" = 'bebo' AND "patients".id  4) LIMIT 1[0m  [4;35;1mPatient Load (0.1ms)[0m   [0mSELECT "patients".id FROM "patients" WHERE ("patients"."l_name" = 'Dixon' AND "patients".date_of_birth = '1986-08-17' AND "patients".f_name = 'Allan ' AND "patients".tel_number = 45345435 AND "patients".id  4)

model code:

class Patient < ActiveRecord::Base

#patient can have many apointments and vistis
has_many :appointments, :dependent => :destroy
has_many :visits, :dependent => :destroy

# adding the photo as an attribute to patient
attr_accessible :photo
has_attached_file :photo, :styles => { :small => "200x200>" }

# validate that fields are not blank
validates_presence_of(:f_name, :l_name, :tel_number, :address)

# validate that fields are numeric
validates_numericality_of(:height, :weight, :bmi, :tel_number)

#v alidate uniqueness of fields and users
validates_uniqueness_of(:email, :universal_ID)
validates_uniqueness_of(:l_name, :case_sensitve => false, :scope => [:date_of_birth, :f_name, :tel_number], :message => "User already existsts")

#validate Email is right format
validates_format_of(:email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :message => "Dosen't look like a real email address, please try again")

#validate the date of birth
validates_inclusion_of(:date_of_birth, :in => Date.civil(1900, 1, 1) .. Date.today, :message => "Must be between the year 1900 and today")


end

谢谢

最佳答案

 # adding the photo as an attribute to patient 
attr_accessible :photo

这是你的问题,也许你想要 attr_accesor 而不是 attr_accesible

关于ruby-on-rails - 我在更新对象后收到一条 "patient successfully updated"消息,但 Rails 中的值保持不变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3533502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com