Search code examples
ruby-on-railsrubycontrolleractioncontroller

Call to action on the same controller


I am learning rails and I have a question
How can I call an action from another in the same controller?

def new
  new_method()
end

private

def new_method
 ...
end

This would be the right way?


Solution

  • The parenthesis is optional in Ruby. But, one action receive a call from client and respond one output. Your private "action" is only a function or method.

    class User
        def create
          make_something(params)
        end
    
        private
        def make_something(params)
          #some implementation
        end
    end