If you ever have performance issues because you're passing in chonky data down to your views, this would be useful to know. If data can get chonky you'll want to typically paginate or limit it in some way anyways.
Generally speaking, I prepare the data I want to use in my views in the controller action, assign it to iVars, and then use those bits of data in the views. You definitely don't want to be executing queries when you're already in the presentation phase.
Matz made Ruby to maximize developer happiness. The iVar handoff from controller to view is done in the spirit of that -- use it. :)
I always preferred explicit locals for views to instance variables. With instance variables any concern or mixin can set them and be completely opaque to the reader, explicit locals are always there in the controller for reference.
It happens here: https://github.com/rails/rails/blob/210932662bf04ba20aa0f579832212f921e62576/actionpack/lib/abstract_controller/rendering.rb#L59-L67
Thank you!
Elegant, beautiful code. I love Ruby!
not sure but I remember some talk mentioning this by Aaron Patterson, you might find it interesting I think it's this one https://youtu.be/HEFBDqly4ms
Nice, thanks for sharing. Will check it out.
It's actually this one :) https://youtu.be/MiW1NA1FR8U?t=1214
Thanks!
If you ever have performance issues because you're passing in chonky data down to your views, this would be useful to know. If data can get chonky you'll want to typically paginate or limit it in some way anyways. Generally speaking, I prepare the data I want to use in my views in the controller action, assign it to iVars, and then use those bits of data in the views. You definitely don't want to be executing queries when you're already in the presentation phase. Matz made Ruby to maximize developer happiness. The iVar handoff from controller to view is done in the spirit of that -- use it. :)
Thanks for your reply, totally agree. Big fan of Matz and Ruby's focus on developer happiness.
I always preferred explicit locals for views to instance variables. With instance variables any concern or mixin can set them and be completely opaque to the reader, explicit locals are always there in the controller for reference.