johno / johno/meta_magic

Safe version of "get_model_class"

Open
#1 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
0
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Currently `get_model_class`, will throw an exception when called in a controller that doesn't correspond with a model.

This seems like behavior you would probably want in many cases, but we ran into a situation yesterday where returning nil would've been nicer for us.

This can be accomplished with
```rb
def get_model_class
controller_name.classify.safe_constantize
end
```
It would be nice to have something like
```rb
get_model_class # returns nil
get_model_class! # exception
```

or if we don't want to change how `get_model_class` returns, then

```rb
safe_get_model_class
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.