To sum it up:
Use @ for instance variables when you want to store data specific to an object (for controllers, views, or models in Rails).
Use local variables for data that only needs to be used within a specific method or block. This keeps things more modular and prevents unnecessary data from leaking outside the scope.
Avoid $ for global variables. They should generally be avoided in Rails applications because they make the code harder to reason about.
If you find yourself needing global variables, you might want to reconsider your design approach. Instead, consider passing state through objects, methods, or classes.