Modify an existing model using the Redmine plugin

The Redmine plugin tutorials explain how to wrap basic models, but I need to add another column to the log table. I need a boolean field inserted in the log model. Creating another model with a "belongs to: magazine" relationship seems redundant. Can this be done using a plugin? I should note that I am new to rails.

+4
source share
2 answers

You just need to create the appropriate migration .

In your plugins directory, create the db/migrate/update_journal.rb with the following:

 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 

Then you can run the rake db:migrate_plugins RAILS_ENV=production task to update the database with a new field.

After the migration is completed, the log database will have a field my_bool , which you can call, like any other field.

+3
source

I was able to extend the existing user model using the following code:

 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 

I also needed to specify the migration file so that it starts with a number, for example. MyPlugin / db / migrates / 001_update_user.rb

0
source

All Articles