1

我正在为 redmine 创建插件。我需要在项目控制器中添加操作。我为ProjectsControllers做了一个补丁

  module ProjectsControllerPatch
  def self.included(base) # :nodoc:
    base.extend(ClassMethods)
    base.send(:include, InstanceMethods)
  end
  module ClassMethods
  end
  module InstanceMethod
     def new_method
     end
  end
end

# Add module to Issue
ProjectsController.send(:include, ProjectsControllerPatch)

并在 routes.rb 中添加了路由:

get 'new_method', :to => 'projets#new_method'

但我在这条路线上有 404 错误

4

1 回答 1

1

您需要像这样定义路线:

RedmineApp::Application.routes.draw do
  match 'issue/:issue_id/something/:action/:id', to: 'something#new_some', as: 'fancy_route'
end

之后在您的插件中注册此路由:

project_module :my_plugin do
  permission :my_plugin, { :my_plugin => [:fancy_route] },:public => true
end

来自 iCalendar 插件的实时示例:

project_module :redmine_icalendar do
  permission :redmine_icalendar, {:redmine_icalendar => [:index, :show, :list]}, :public => true
  permission :redmine_icalendar, {:redmine_icalendar => [:edit, :new, :destroy]}, :require => :member    
end
于 2013-08-09T05:31:23.557 回答