Redmine 플러그인으로 기존 모델을 변경하십시오
-
19-09-2019 - |
문제
Redmine 플러그인 튜토리얼은 핵심 모델을 랩핑하는 방법을 설명하지만 필요한 것은 저널 테이블에 다른 열을 추가하는 것입니다. 저널 모델에 부울 필드가 필요합니다. 'selts_to : Journal'관계로 다른 모델을 만드는 것은 과잉처럼 보입니다. 플러그인으로 수행 할 수 있습니까? 나는 내가 레일 초보자라는 점에 주목해야한다.
해결책
당신은 그냥 적절한 것을 만들어야합니다 이주.
플러그인 디렉토리에서 파일을 만듭니다 db/migrate/update_journal.rb
다음과 함께 :
class UpdateJournal < ActiveRecord::Migration
def self.up
change_table :journal do |t|
t.column :my_bool, :boolean
end
end
def self.down
change_table :journal do |t|
t.remove :my_bool
end
end
end
그런 다음 작업을 실행할 수 있습니다 rake db:migrate_plugins RAILS_ENV=production
새 필드로 데이터베이스를 업데이트합니다.
마이그레이션을 실행 한 후에는 저널 데이터베이스가 my_bool
다른 모든 분야처럼 전화 할 수있는 필드.
다른 팁
다음 코드를 사용하여 기존 사용자 모델을 확장 할 수있었습니다.
class UpdateUsers < ActiveRecord::Migration
def up
add_column :users, :your_new_column, :string, :default => ''
add_column :users, :your_other_new_column, :string, :default => ''
end
def down
remove_column :users, :your_new_column
remove_column :users, :your_other_new_column
end
end
또한 마이그레이션 파일을 숫자로 시작한 방식으로 이름을 지정해야했습니다. myplugin/db/migrate/001_update_user.rb
제휴하지 않습니다 StackOverflow