Rails controller update record by copying field -


i have rails 3.2 app copy contents of 1 field in controller action.

costprojects contains these 2 columns:

original_year project_year 

i want copy contents of project_year original_year.

i tried doing this:

    update = costproject.where(:id => @costprojects).update_all(:original_year => :project_year) 

i error:

pg::error: error:  invalid input syntax integer: "project_year" 

line 1: update "costprojects" set "original_year" = 'project_year' w...

                                                ^ 

thanks help!

please try :

costproject.where(:id => @costprojects)            .update_all("original_year = project_year") 

with former code:

update_all(:original_year => :project_year) 

it trying update integer field original_year string value project_year. that's why got error.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -