---
title: 'This week in #dev (Nov 29, 2024)'
teaser: 'How to check if you''re in a local Rails env and localizing models with Active
  Model.

  '
tags: this week in dev,rails,til,tip
author: thoughtbot
published_on: 2024-12-10
---

Welcome to another edition of [This Week in #dev](https://thoughtbot.com/blog/tags/this-week-in-dev),
a series of posts where we bring some of our most interesting Slack
conversations to the public.

## Understanding `Rails.env.local?`

[Neil Carvalho][neilson] shares a tip: [`Rails.env.local?`] returns true if the environment is either development or test.

[neilson]: https://thoughtbot.com/blog/authors/neil-carvalho
[`Rails.env.local?`]: https://api.rubyonrails.org/classes/Rails.html#method-c-env

## Localizing models with Active Model

[Joël Quenneville][joelq] shares some exciting tips about ActiveModel. By using `ActiveModel::Naming` and `ActiveModel::Translation`, model-level translations can be applied to both persisted and in-memory models, like a `Guest` object for anonymous users. With a locale file, you can localize model and attribute names:

```yaml
en:
  activemodel:
    models:
      guest: Customer
    attributes:
      guest:
        login: "Handle"
```

This allows access to methods for localized names:

```ruby
@user.model_name.i18n_key           #=> :guest
@user.model_name.human              #=> "Customer"
@user.human_attribute_name("login") # => "Handle"
```

Additionally, Rails validation errors will also be localized. For more information, check out these resources:

- [Translations for models (Rails Guides)](https://guides.rubyonrails.org/i18n.html#translations-for-active-record-models)
- [ActiveModel::Naming](https://api.rubyonrails.org/classes/ActiveModel/Naming.html)
- [ActiveModel::Translation](https://api.rubyonrails.org/classes/ActiveModel/Translation.html)

[joelq]: https://thoughtbot.com/blog/authors/joel-quenneville

## Thanks

This edition was brought to you by [Joël Quenneville][joelq] and [Neil Carvalho][neilson]. Thanks to all contributors! 🎉
