Project

General

Profile

Rails 3 porting issues

Added by John Yani over 12 years ago

I had some issues when porting Redmine 1.x plugin to Redmine from trunk with Rails 3 support.
First of all, a plugin requires some preinitialization, so it contained the following in init.rb:

   require 'dispatcher'

   Dispatcher.to_prepare do
   # initialization
   end

In Rails 3 this method http://apidock.com/rails/v3.0.9/ActionController/Dispatcher/to_prepare/class was moved to Rails::Railtie::Configuration#to_prepare

If a redmine plugin was a Railtie I could do this:

  config.to_prepare do
  # initialization
  end

This didn't work. So I used this:

  Rails.configuration.to_prepare do
  # initialization
  end

Now I have another issue: routes. Apparently I can't use

  Redmine::Application.routes.draw do

because Redmine is undefined. Why is that?


Replies (21)

RE: Rails 3 porting issues - Added by Kirill Bezrukov (RedmineUP) over 12 years ago

I have problem with include PluginHelper inside path file. Looks like plugins helpers path does not added to the global path

RE: Rails 3 porting issues - Added by John Yani over 12 years ago

Kirill Bezrukov wrote:

PluginHelp_d_er

Are you sure you spelled correctly?

RE: Rails 3 porting issues - Added by Kirill Bezrukov (RedmineUP) over 12 years ago

Sorry just mistake.

and

require "contacts_helper" 

does not work in

module RedmineContacts
  module Hooks
    class ViewsIssuesHook < Redmine::Hook::ViewListener     
      require "contacts_helper" 

      render_on :view_issues_sidebar_planning_bottom, :partial => "issues/contacts", :locals => {:contact_issue => @issue}  

      def view_issues_index_bottom(context={})
        stylesheet_link_tag :contacts, :plugin => 'redmine_contacts'
      end

    end   
  end
end

RE: Rails 3 porting issues - Added by Kirill Bezrukov (RedmineUP) over 12 years ago

RedmineApp::Application.routes.draw works for me

RE: Rails 3 porting issues - Added by John Yani over 12 years ago

So, you want methods from your app/helpers/contacts_helper.rb to be included to your lib/contacts_hooks.rb? Why don't you wrap them to ContactsHelper module and use include ContactsHelper?

RE: Rails 3 porting issues - Added by Kirill Bezrukov (RedmineUP) over 12 years ago

I want to use contacts_helper methods in app/views/issues/_contacts.html.erb partial. Maybe it is not the best example. In common case I can't include, require or :helper inside lib/patches

RE: Rails 3 porting issues - Added by John Yani over 12 years ago

Kirill Bezrukov wrote:

I want to use contacts_helper methods in app/views/issues/_contacts.html.erb partial.

So use them. They are required automatically.

RE: Rails 3 porting issues - Added by Jean-Philippe Lang over 12 years ago

John Yani wrote:

Now I have another issue: routes. Apparently I can't use

[...]

because Redmine is undefined. Why is that?

Have a look at extra/sample_plugin/config/routes.rb.

RE: Rails 3 porting issues - Added by John Yani over 12 years ago

Another problem I had is that there is no replacement for

Engines::RailsExtensions::AssetHelpers.plugin_asset_path

I used it to keep jquery css and js in one folder.

So I was forced to split them.

RE: Rails 3 porting issues - Added by Sergey Kolchenko over 12 years ago

It works for me:

RedmineApp::Application.routes.draw do
  match 'checklist/done/:checklist_item_id' => 'issue_checklists#done'
  match 'checklist/delete/:checklist_item_id' => 'issue_checklists#delete'
end

RE: Rails 3 porting issues - Added by Andriy Lesyuk about 12 years ago

I'm getting weird behaviour with CustomFieldFormat registering... Sometimes it is seen in the available_formats list other time it is not...

RE: Rails 3 porting issues - Added by Andriy Lesyuk about 12 years ago

Ok, it seems that in:

validates_inclusion_of :field_format, :in => Redmine::CustomFieldFormat.available_formats

The :in array is cached...

RE: Rails 3 porting issues - Added by Kirill Bezrukov (RedmineUP) about 12 years ago

I have problems with testing plugins in Redmine 2.1 - can't load redmine and plugin fixtures in same time

class ContactsControllerTest < ActionController::TestCase  
  self.fixture_path = File.dirname(__FILE__) + "/../fixtures/" 

if add that line, plugin fixtures load fine, but redmine not. If not add, I have opposite case.

Any ideas about it?

RE: Rails 3 porting issues - Added by Alex Shulgin almost 12 years ago

Hello there!

I'm also having a problem using 'helper' method in controller. This worked before with pre-2.x versions of Redmine.

I'm getting a LoadError:

activesupport-3.2.6/lib/active_support/dependencies.rb:317:in `rescue in depend_on': Missing helper file helpers/canned_responses_helper.rb (LoadError)

in this code:

module RedmineCannedResponses
  module ProjectsControllerPatch
    def self.included(base)
      base.class_eval do
        helper :canned_responses  # <= HERE
      end
    end
  end
end

The helper file is there, under app/helper/ in my plugin's directory. Are not these added to the load path anymore?

Thank you.
--
Alex

RE: Rails 3 porting issues - Added by Etienne Massip almost 12 years ago

Alex Shulgin wrote:

The helper file is there, under app/helper/ in my plugin's directory. Are not these added to the load path anymore?

You mean app/helpers/?

RE: Rails 3 porting issues - Added by Kirill Bezrukov (RedmineUP) almost 12 years ago

I had the same problem. But it's gone after some manipulations with require_dependense. I think, the point it about loading order.
In new plugins I can't solve it.

RE: Rails 3 porting issues - Added by Alex Shulgin almost 12 years ago

Etienne Massip wrote:

Alex Shulgin wrote:

The helper file is there, under app/helper/ in my plugin's directory. Are not these added to the load path anymore?

You mean app/helpers/?

Yes, that was a typo. And won't work with pre-2.x either if the dir name was spelled incorrectly, but it did work.

Thanks.
--
Alex

RE: Rails 3 porting issues - Added by Alex Shulgin almost 12 years ago

Kirill Bezrukov wrote:

I had the same problem. But it's gone after some manipulations with require_dependense. I think, the point it about loading order.
In new plugins I can't solve it.

Bingo! Seems like Redmine::Plugin.register is the point where app paths are added to load path. Moved my patch calls after that and it is working now.

RE: Rails 3 porting issues - Added by Daniel Felix almost 11 years ago

Well, I'm not sure if the Rails 3 porting is still an important thread here?

RE: Rails 3 porting issues - Added by Anonymous about 5 years ago

Alex Shulgin wrote:

Etienne Massip wrote:

Alex Shulgin wrote:

The helper file is there, under app/helper/ in my plugin's directory. Are not these added to the load path anymore?

You mean app/helpers/?

Yes, that was a typo. And won't work with pre-2.x either if the dir name was spelled incorrectly, but it did work.

Thanks.
--
Alex

So, you want methods from your app/helpers/contacts_helper.rb to be included to your lib/contacts_hooks.rb? Why don't you wrap them to ContactsHelper module and use include ContactsHelper?

    (1-21/21)