Search⌘ K

Reference Data, Global Context, and UI State Are Exceptions

Explore how to manage reference data like country codes, global context such as the current user, and UI state in Rails views. Understand why these cases are exceptions to the one instance variable per view rule and how to keep code clear by leveraging controllers and instance variables for easy traceability.

Managing specialized data in Rails applications

Almost every Rails app has a method called current_user that exposes an object representing who is logged in. It’s also common to need a list of reference data, such as country codes, in order to build a drop-down menu or other piece of UI. Lastly, it’s common to need to persist UI state between requests, such as for a tabbed-navigation control. None of these make sense as part of an existing ...