0

I am using Ruby on Rails 3.0.9 and I would like to pass some variables to an helper_method stated in my controller.

class ArticlesController < ApplicationController
  helper_method :method_name

  private

  def method_name # Here I would like to state\use something like 'def method_name(var1, var2)'
    ...
  end
end

Is it possible? If so, how should I code and how can I use that?

Backo
  • 18,291
  • 27
  • 103
  • 170

1 Answers1

0

To write a function you do this:

def method_name (param1,param2)

to call a function you do this:

method_name (arg1, arg2)

theRealWorld
  • 1,188
  • 2
  • 8
  • 23
  • I would like to state a method as you have stated and then make that to work (also) as an 'helper_method'. – Backo Jul 26 '11 at 08:22
  • each controller has it's own helper file or you can write helpers in the application helper file. it does not matter whether you have a helper method or not. passing variables is exactly the same. – theRealWorld Jul 26 '11 at 08:32
  • 2
    So, can you be more prolific in your answer? I do not understand what you mean. – Backo Jul 26 '11 at 08:47
  • [this](http://paulsturgess.co.uk/articles/49-using-helper-methods-in-ruby-on-rails) might help. Let me know if you still don't get it. – theRealWorld Jul 26 '11 at 08:59
  • 2
    @theRealWorld link is broken – Magne Jun 16 '17 at 16:13