Book Image

Redmine Plugin Extension and Development

By : Alex Bevilacqua
Book Image

Redmine Plugin Extension and Development

By: Alex Bevilacqua

Overview of this book

Table of Contents (16 chapters)
Redmine Plugin Extension and Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Model preparation


Redmine has implemented a number of internal plugins, which are located under /path/to/redmine/lib/plugins.

These plugins follow the traditional Rails naming idiom of acts_as_* (for more information on this topic, visit http://guides.rubyonrails.org/plugins.html#add-an-acts-as-method-to-active-record), which implies that we'll be including a class level method, which is named the same as the plugin.

The class we'll be extending is the model that our knowledgebase plugin uses to manage articles.

class KbArticle < ActiveRecord::Base
  validates :title, :presence => true
  validates :category_id, :presence => true

  belongs_to :project
  belongs_to :category, :class_name => "KbCategory"
  belongs_to :author,   :class_name => 'User',:foreign_key => 'author_id'

  # class method from Redmine::Acts::Attachable::ClassMethods
  acts_as_attachable

  # class definition continues ...  
End

By including acts_as_attachable in our class, a has-many association is established...