Best Practices for reusing code between controllers in Ruby on Rails

前端 未结 7 722
忘掉有多难
忘掉有多难 2020-11-29 16:06

I have some controller methods I\'d like to share. What is the best practice for doing this in ruby on rails? Should I create an abstract class that my controllers extend, o

7条回答
  •  庸人自扰
    2020-11-29 16:29

    I agree with the module approach. Create a separate Ruby file in your lib directory and put the module in the new file.

    The most obvious way would be to add the methods to your ApplicationController, but I am sure you know that already.

提交回复
热议问题