2

I don't know Ruby&Rails, but I would like to build a small custom Redmine plugin for my personal needs. And I have faced with the problem which might look quite straightforward for Ruby experts. I have two helpers (modules):

  • helper1

  • helper2

And I would like to use helper1.method1 inside of helper2.method3. I have tried following to achieve this:

  • simply call method helper1.method1 inside helper2.method3, with thoughts that relations resolved automatically - didn't work;

  • require helper1 inside helper2 by require '../../relative/path'- didn't worked;

  • require helper1 inside helper2 by require '../../relative/path'- didn't worked;

  • included helper1 inside helper2- didn't worked

I have tried to find information how proper to call a method from one custom helper inside of another custom helper but didn't found any relevant results. The most of results were about how to call custom helper method inside view, controller, settings view.

So, could somebody explain to me how properly use methods from one custom helper inside of another one?

Best, regards.

1
  • I think you can try to include both helper modules to you controller class (for example github.com/twinslash/redmine_omniauth_google/blob/…). Not sure but I think if methods from included helpers are accessible in controller then these methods can be called from each other. Commented Mar 3, 2018 at 12:58

1 Answer 1

1

For common functionality I would suggest to

  1. create a module in the lib folder (e.g. lib/my_plugin/common_code.rb)
  2. require it in the plugins init.rb:

    ActionDispatch::Callbacks.to_prepare do 
      require 'my_plugin/common_code'
    end
    
  3. include it in each helper it is needed

    include MyPlugin::CommonCode
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.