0

I'm writing a redmine plugin where model is Allissue. I added two attributes project_name and create_date. First, I added column project_name and assigned them some values. Second, I added one more column created_date for which values become null as shown in figure. enter image description here

I want to replace null with integer values. It is very basic question but I don't know as I'm a newbie. Can you suggest me the syntax to add values. Thanks

Dipendra Singh
  • 542
  • 1
  • 6
  • 23

1 Answers1

1

For this to happen automatically, add something like this to your model:

class Allissue
  ...
  before_save do |a|
    a.create_date = Time.now # or whatever you want it to be
  end
  ...
end

or manually, you would do (for all multiple objects):

Allissue.all.each{|a| a.create_date = Time.now; a.save}

or (for a single object):

a = Allissue.find(1)
a.create_date = Time.now
a.save

I hope this helps.

moritz
  • 25,477
  • 3
  • 41
  • 36
  • thanks...but create_date is not a Magic columns so I can't relate it with Time.now. It depends on project perspective. – Dipendra Singh Jul 23 '12 at 08:54
  • Can u answer my another [question]:(http://stackoverflow.com/questions/11607405/plugin-migrations-for-redmine-place-plugin-in-db-migrate-instead-of-plugin-fold) – Dipendra Singh Jul 23 '12 at 08:57