B
B
Bogdan2018-02-06 14:36:28
Ruby on Rails
Bogdan, 2018-02-06 14:36:28

How to correctly call a controller method from another controller?

Hello. Tell me please. How to correctly call a method from another controller.
Which option is preferable
1) make the method public through ApplicationController
2) call it by creating an object Institution::MenuRequirementsController.new.update_prices()
3) or declare the method through self, and then call it Institution::MenuRequirementsController.update_prices
Or is there another solution. Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
blackst0ne, 2018-02-06
@blackst0ne

If the method is shared, then you can either move it to a common parent, or move it to a module/concern and connect it further in the standard way.

A
Alexander Leonchik, 2018-02-06
@AlexanderMint

Such a task should not arise, your design approach is not correct. You can use trailblazer opertaion , dry-transaction or dry-contaioner to take some common functionality out. Everything depends on the task.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question