mysql - ".save" only inserts null values in database -


i'm trying make ror application hospital has patients, doctors, offices, etc.

the problem i'm having that, @ patient "sign-up", i'm not able save new patient in database. in fact, despite i've checked attributes ok (it's name , personal id), once method excecuted, in database appears new row "<null>" instead of actual attribute values. here's method:

def pat_create    pname = params[:name].to_s   id    = params[:pid].to_s.to_i    pat = patient.where(:pid => id).first   if pat == nil     pat = patient.new(:name => pname, :pid =>id)     pat.save   end  end 

also, query constructs:

insert `patients` (`created_at`, `name`, `pid`, `updated_at`) values ('2013-05-20 02:04:28', null, null, '2013-05-20 02:04:28') 

this method called after other view collects :name , :pid information in form:

<%= form_tag('/page/pat_create') %>    <%= text_field_tag :name, nil%>    <%= text_field_tag :pid, nil%>    <%= button_tag(type: "submit", class: "btn btn-success") %>      register<i class="icon-white icon-plus"></i>    <%end%>  <%end%> 

needless say, pat.errors.empty? true, , pat.save.

any idea why happens?

here's patient model:

class patient < activerecord::base    attr_accessible :name, :pid   attr_accessor :name, :pid    has_many :appointments   validates_presence_of :name   validates :name, :format => {:with=> /^[a-za-z\s\d]+$/}   validates_presence_of :pid   validates_numericality_of :pid   validates_inclusion_of :pid, :in => 100000..9999999999     end 

remove following line in class patient:

attr_accessor :name, :pid 

what happened attr_accessor replaced 2 database column attributes :name , :pid (which automatically generated) own, resulting in 2 virtual attributes, :name , :pid.

thus, virtual attributes being set , validated instead of corresponding database attributes, resulted in no errors yet null values in database.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -