Instead of using andand or try , I would do:
if env.fetch("rack.request.form_hash", {})["authenticity_token"].to_s.gsub("\r\n",'')
or add to_hash to the list of useful NilClass methods ( to_a , to_s , to_i , etc.):
class NilClass; def to_hash; {} end end
and execute:
if env["rack.request.form_hash"].to_hash["authenticity_token"].to_s.gsub("\r\n",'')
source share