Вместо того, чтобы использовать andand
или try
, я бы сделал:
if env.fetch("rack.request.form_hash", {})["authenticity_token"].to_s.gsub("\r\n",'')
или добавлю to_hash
в список полезных NilClass
методов (to_a
, to_s
,to_i
и т. Д.):
class NilClass; def to_hash; {} end end
и выполните:
if env["rack.request.form_hash"].to_hash["authenticity_token"].to_s.gsub("\r\n",'')