Feature feedback before working and pull request please..


As you can see, the post belongs to a user and I am printing out the user display name for every post.

This is a pretty common thing in every rails app I ever saw, some preload, some let it go N+1 without caring.

The problem is, that if you don’t have the user in the database, the view code will fail on NoMethodError for NilClass.

that is exactly why we have #try:

<%= post.try(:user) { |u| u.display_name } || “Unknown user” %>

Wouldn’t it be preferable to avoid basing the default behavior on the mere existence of a class?

It could easily bite back, in case a ruby gem you use (or one of its dependencies) defines such a class.

(Note that I’m personally very happy to get exceptions when the subject is nil, or to use try or similar helpers when I do not want that)

– Thibaut