I'm looking for a part-time remote job.

Hire me


I'm the author of:

Mastering Redmine is a comprehensive guide with tips, tricks and best practices, and an easy-to-learn structure.

Check the book's project or

Buy the book

Social pages of the book:

By buying this book you also donate to Redmine (see this page).


Follow me:

Porting plugins to Redmine 2

No Dispatcher

Instead of Dispatcher we use:

Rails.configuration.to_prepare do
    ...
end

Observer cannot be loaded

Under Redmine 2 observers sometimes get loaded, sometimes do not get loaded...

To fix this we use:

require_dependency File.expand_path(File.join(File.dirname(__FILE__), 'app/models/repository_observer'))

ActiveRecord::Base.observers << RepositoryObserver

Validators now cache arguments

For example, Redmine::CustomFieldFormat.register can be used to add new custom field types. However, since Rails 3 an array passed to the :in argument of validates_inclusion_of is retrieved only once and gets cached.

In most cases, issues related to this change can be resolved by changing the position where Redmine::CustomFieldFormat.register is invoked.

Disabling validation on save

Code object.save(false) does not work more. Instead use:

object.save(:validate => false)

add_to_base is now deprecated

Anyway add_to_base(...) always used add(:base, ...)

form_tag now returns form content

Before we wrote:

<% form_tag(...

Now we need to write:

<%= form_tag(...

To support current and previous versions we do:

<% form = form_tag(...) do
     ...
   end %>
<%= form if Rails::VERSION::MAJOR >= 3 %>

Text gets HTML-escaped

Now you can't print string like <tag>content</tag> into view as it will be escaped and shown as it is.

Instead you should use html_safe:

'<br />'.html_safe

But for tags like <br /> you should better use HTML helpers, e.g. tag(:br).

Routing changes

In Rails 3 routing was completely rewritten. There is no other way besides rewriting your config/routes.rb.

I used the following code to support both Rails:

if Rails::VERSION::MAJOR < 3
    ... # old code
else
    ... # new code
end

RAILS_DEFAULT_LOGGER disappeared

It's safe to replace it with just Rails.logger...

As well as RAILS_ROOT

But, again, Rails.root can be used instead.

Prototype was replaced by jQuery

For example, Rails 3 now does not provide the observe_field function as it was used for Prototype... So this function can be used to check what JavaScript library is used by Redmine:

<!-- Rails 2 + prototype -->
<% if defined? observe_field %>
  <%= javascript_include_tag('extended_prototype', :plugin => 'extended_fields') %>
<!-- Rails 3 + jQuery -->
<% else %>
  <%= javascript_include_tag('extended_jquery', :plugin => 'extended_fields') %>
<% end %>

No remote_form_for and link_to_remote

Due to switch to jQuery many functions disappeared. Most of them can be replaced by their closest equivalent but with new :remote option. Thus:

  • :remote_form_for can be replaced by form_for(..., :remote => true)
  • :link_to_remote can be replaced by link_to(..., :remote => true)

No RJS

It's also related to the switch to jQuery...

There were times, when you could write in your controller:

format.js do
    render :update do |page|
        page.replace_html('html-element-id', :partial => 'path/to/partial')
        page.visual_effect(:fade, 'html-element-id', :delay => 1.0)
        page << 'JavaScript_Code();'
    end
end

These times were good, were not they?.. You can't do this no more! That was possible thanks to RJS, which has been removed in Rails 3.1.x.

Now you need to define action.js.erb with JavaScript code in it, e.g.:

$('#html-element-id').html('<%= escape_javascript(render(:partial => 'path/to/partial')) %>');

And remove any render* commands from format.js { ... }...

Template extensions requirement

I used *.rhtml extension to overwrite template files. Redmine 2.0 does not support it anymore . Now in order to work the extension should be *.html.erb.

Plugin directory name requirement

Before if the name of plugin in init.rb was e.g. :redmine_scm_plugin the directory could be named just redmine_scm. Now the plugin name should be :redmine_scm! This solves many issues.

Migration command changed

To migrate users should now execute:

rake redmine:plugins:migrate RAILS_ENV=production

Thanks

Thanks to Takashi Okamoto for assisting!

Terms of use | Privacy policy