Redmine: plug-in development-extended models, Controller, and view

Source: Internet
Author: User
Tags redmine

Http://www.redmine.org/wiki/redmine/Plugins

Http://www.redmine.org/wiki/redmine/Plugin_Internals

 

Overriding the redmine Core

You can override views but not controllers or models in redmine. Here's how redmine/rails works if you try to override a controller (or model) and a view for a fictional pluginMyplugin:

Controllers (or models)
    1. Rails bootstraps and loads all it's Framework
    2. Rails starts to load code in the plugins
    3. Rails findsIssuecontrollerIn myplugin and see it definesShowAction
    4. Rails loads all the other plugins
    5. Rails then loads the application from../APP
    6. Rails findsIssuecontrollerAgain and see it also definesShowAction
    7. Rails (or rather Ruby) overwritesShowAction from the plugin with the one from../APP
    8. Rails finishes loading and serves up requests
Views

View loading is very similar but with one small difference (because of redmine's patch to engines)

    1. rails bootstraps and loads all it's framework
    2. rails starts to load code in the Plugins
    3. rails finds a views directory in .. /vendor/plugins/my_plugin/APP/views and pre-pends it to the Views path
    4. rails loads all the other plugins
    5. rails then loads the application from ../APP
    6. rails finishes loading and serves up requests
    7. request comes in, and a view needs to be rendered
    8. rails looks for a matching template and loads the plugin's template since it was pre-pended to the Views path
    9. rails renders the Plugins 'view

Due to the fact that it is so easy to extend models and controllers the Ruby way (via including modules), redmine shouldn't (and doesn't) maintain an API for overriding the core's models and/or controllers.Views on the other hand are tricky (because of rails magic) So an API for overriding them is way more useful (and thus implemented in redmine ).

To override an existing redmine core view just create a View File named exactly after the one in../APP/views/And redmine will use it. for example to override the project index page add a file../Vendor/plugins/my_plugin/APP/views/projects/index. rhtml.

 

Extending the redmine Core

As explained above: You rarely want to override a model/controller. Instead you shoshould either:

    • Add new methods to a model/controller or
    • Wrap an existing method.
Adding a new method

A quick exampleAdding a new methodCan be found on Eric Davis'Budget plugin. Here he added a new method to issue calledDeliverable_subjectAnd also declared a relationship.

Wrapping an existing Method

A quick exampleWrapping an existing MethodCan be found on Eric Davis'Rate plugin. Here he usesAlias_method_chainTo hook into the usershelper and wrapUser_settings_tabsMethod. So when the redmine core CILSUser_settings_tabsThe codepath looks like:

    1. Redmine core CILSUsershelper # user_settings_tabs
    2. Usershelper # user_settings_tabsRuns (which is actuallyUsershelper # user_settings_tabs_with_rate_tab)
    3. Usershelper # user_settings_tabs_with_rate_tabCallthe originalUsershelper # user_settings_tabs(RenamedUsershelper # user_settings_tabs_without_rate_tab)
    4. The result then has a new hash added to it
    5. Usershelper # user_settings_tabs_with_rate_tabReturns the combined result to the redmine core, which is then rendered

Alias_method_chainIs a pretty advanced method but it's also really powerful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.