Best Practices for reusing code between controllers in Ruby on Rails

前端 未结 7 733
忘掉有多难
忘掉有多难 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:53

    Another possibility:

    If your common code needs state and you want to share the behavior amongst controllers, you could put it in a plain old ruby class in either your model or lib directory. Remember that model classes don't have to be persistent even though all ActiveRecord classes are persistent. In other words, it's acceptable to have transient model classes.

提交回复
热议问题