我正在为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错误
答案 0 :(得分:0)
你需要定义这样的路线:
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