Skip to content

Instantly share code, notes, and snippets.

@svoboda-jan
Created January 23, 2014 19:37
Show Gist options
  • Save svoboda-jan/8585342 to your computer and use it in GitHub Desktop.
Save svoboda-jan/8585342 to your computer and use it in GitHub Desktop.
This is a simple example of how to create a redmine plugin, which adds a new custom field format to allow dynamic values to be used as options for custom fields
# redmine/plugins/project_author/db/migrate/001_add_author_to_project.rb
class AddAuthorToProject < ActiveRecord::Migration
def up
ProjectCustomField.create(
name: 'Author',
field_format: 'all_users',
default_value: nil,
is_required: false,
editable: true,
visible: true
)
end
def down
ProjectCustomField.where(name: 'Author').first.try :destroy
end
end
# redmine/plugins/project_author/app/models/all_users_field_format.rb
class AllUsersFieldFormat < Redmine::FieldFormat::List
def possible_values_options(custom_field, object=nil)
User.all.collect { |u| [ u.to_s, u.id.to_s ] }
end
end
Redmine::Plugin.register :project_author do
name 'Project Author plugin'
author 'Jan Svoboda'
description 'This is a plugin for Redmine to specify author for each project'
version '0.0.1'
author_url 'https://github.com/svoboda-jan'
end
Redmine::FieldFormat.add 'all_users', AllUsersFieldFormat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment