Safe version of "get_model_class"
Open
- 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.