Hi
Sorry i really didn't know how to phrase the question any better but here is my problem:
when i try to update or create a patient object in my rails application the values are not getting sent through to the model, because when i try to create a new patient i get validation errors that i put in place sating i have to enter values (which i did), and when i update an existing patient object the values don't change even though i get the message of "successfully updated patient"
any ideas why that might be?
it used to work fine and i didn't change anything in the patient controller or model for it to stop working?
if you need any code from me please just let me know what u need.
controller create and update code:
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
server Log:
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"=>"[email protected]", "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" = '[email protected]' 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
thanks