ruby on rails - Opening an existing class in Redmine Plugin file -
i'm writing plugin on redmine.
i want add new method inside existing controller of redmine. controller name repositories.
i wrote in repositories.rb following code:
class repositoriescontroller < applicationcontroller def exec_client ... end end
in routes.rb put:
match '/projects/:id/repository', :controller => 'repositories', :action => 'exec_client', :via => :post
in view navigation.html.erb wrote:
<%= button_to_function l(:gerar_build_project), remote_function(:action => 'exec_client', :controller => 'repositories')%>
the code of class repositoriescontroller written on file repositories_controller.rb.
but, when click in button i've created in view, following message:
abstractcontroller::actionnotfound (the action 'exec_client' not found repositoriescontroller):
what's going wrong?
to extend class in redmine plugin , add new methods, need follow these steps:
in path plugin/lib/client created file client.rb
#encoding: utf-8 module repositoriespatch require_dependency 'repositories_controller' def self.included(base) base.send(:include, instancemethods) end end module instancemethods require_dependency 'repositories_controller' def exec_client [....] end end rails.configuration.to_prepare repositoriescontroller.send(:include, repositoriespatch) end
above created patch new function repositores_controller , have inserted using command .send
in init.rb put:
rails.configuration.to_prepare repositoriescontroller.send(:include, repositoriespatch) end
the rest stood same. hope can useful someone. thanks!
Comments
Post a Comment