문제

Using Rails and MYSQL. Existing table has a column called c1, I would like to add a column called c2 with data func(c1), func is the model method to deal with c1 data. How should I write the migration? Thanks

도움이 되었습니까?

해결책

  1. rails generate migration add_something_to_tablename something:string

  2. rake db:migrate

  3. Inside that model

add this line

before_save :do_something

add this method

private
  def do_something
    do something with c1
  end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top