In this article , we are going to develop Hello World ! plugin with Redmine. For this tutorial , we have used Ubuntu 20.04 LTS as a base and Redmine 4.1.1 also Ruby version is 2.7 .
Note : Before getting started we assume that you have a working Redmine installation.
Step 1: Develop Hello World! plugin with redmine plugin generator
open terminal and change your current directory to your redmine installation directory i.e. /usr/share/redmine-4.1.1. Use following command,
cd /usr/share/redmine-4.1.1/
Now , here we will create plugin using redmine plugin generator script, use following command to generate plugin .
export RAILS_ENV=”production”
above command will set rails environment variable to production and now generator script.
bundle exec ruby bin/rails generate redmine_plugin hello
here hello is the name of plugin , you can replace it with name of your choice if you want .
This command will generate all the plugin directories and init.rb file that is used by redmine to detect and configure new plugin.
Here , app directory is where most of work is done . In app directory all the models , controllers and views are stored.
Step 2- Creating a controller and view using controller generator
For , hello world application , we need to create one controller and one view . The controller will render the associated view and view which is made od templates act as interface.
Controller generator creates a blank controller ( a ruby class) with its functions and associated views ( ruby embedded HTML files) .
use following command to generate a controller
bundle exec ruby bin/rails generate redmine_plugin_controller <plugin_name> <controller_name> [actions]
here plugin name will be “hello” , controller name lets say “one” and action “index ” . You can customize controller and action names but you have to make appropriet changes in further steps .
bundle exec ruby bin/rails generate redmine_plugin_controller hello one index
here controller is a ruby class and actions are methods of that class. The generator script will create empty controller with an empty view associated with a action.
Note : there will be separate view template associated with each controller action . And all templates will be stored in same folder named same as of controller name .
In order to develop Hello World ! plugin with Redmine following steps are important, so we tried to document it carefully.
Step 3 – Customizing empty controllers and views
This plugin does not need any functionality or any calculations so our controller program will remain as it is . But we will add one <h1> tag inside view program .
step 4- Adding Route for controller
adding just controller and view is not enough . Controller renders associated views when controller itself is activated . We need to add route in routes.rb file located inside config directory of plugin so that controller is activated .
add following route in routes.rb file
get ‘one’,:to=>’one#index’
Step 5 – Migrating and activating plugin
enter following command to migrate plugin data
RAILS_ENV=production bundle exec rake db:migrate
Now restart redmine and visit http://localhost:3000/one to see working hello world plugin .
This is all about your first Develop Hello World! Plugin With Redmine, let us know your feedback and happy plugin development.