Is there a clean way to avoid calling a method on nil in a nested params hash? [duplicate]

Check Ick‘s maybe. You don’t need to significantly refactor your code, just intersperse maybe proxies when necessary:

params[:subject].maybe[:name]

The same author (raganwald) also wrote andand, with the same idea.

Leave a Comment