5

Question, can you have private and protected in a single Ruby on Rails controller? If not, which one is preferred in a devise controller, or a regular controller for a model?

Thanks

Corey
  • 735
  • 1
  • 7
  • 29
  • A Rails controller is just a Ruby class. You can have anything in a Rails controller that you can have in a Ruby class, so yes, you can have both in the same class, and the reasons to use one or the other are the same as they are for any Ruby class. – Jordan Running Feb 10 '17 at 16:36

1 Answers1

16

can you have private and protected in a single Ruby on Rails controller?

Yes, you can. Rails controllers are just classes, and classes can have any number and combination of private and protected blocks.

Use protected if you want to allow for inherited controllers to access the method. Use private if you want the method to be accessible only by the controller itself.

user229044
  • 222,134
  • 40
  • 319
  • 330