简体   繁体   中英

Rails writing a record to a table

I'm a newbie. I have a table called statuses. It contains status changes for records in a table called requests.

When a user creates a new request, I'd like to write a record to statuses.

How would I go about that?

Thanks

You can use after_save callback:

class Record < ActiveRecord::Base

  after_save :add_status_chanage

  def add_status_change
    status = Status.new
    status.record_id = id
    status.field = field
    status.save
  end

end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM