The “magic” ivar wormhole between controllers and partials is the single worst design of Rails views, and the framework would be far better off discarding this misfeature.
It’s bad for programmers because it violates the rules of how ivars work everywhere else, thereby creating confusion; and it hides the implicit interface required by the view, making you more likely to miss setting a variable. Interfaces should be explicit and obvious.
I feel like one of the main advantages of components as distinct from partials in Rails is that you get clearer semantics regarding passing things around/where things come from. While this doesn’t eliminate that (you still have to define an attr_writer) it does make it a bit less clear than it otherwise could be (where is @post set?).
The “magic” ivar wormhole between controllers and partials is the single worst design of Rails views, and the framework would be far better off discarding this misfeature.
It’s bad for programmers because it violates the rules of how ivars work everywhere else, thereby creating confusion; and it hides the implicit interface required by the view, making you more likely to miss setting a variable. Interfaces should be explicit and obvious.
A better approach is possible.
I feel like one of the main advantages of components as distinct from partials in Rails is that you get clearer semantics regarding passing things around/where things come from. While this doesn’t eliminate that (you still have to define an
attr_writer) it does make it a bit less clear than it otherwise could be (where is@postset?).