using nil or [] on rails 2.3.8 -
i've strange situation rails application (2.3.8)
i want assign no nil value variable in controller, wrote code:
@myvalue = session[:value] or [] in view wrote:
<%= @myvalue.size %> when display page, have nil error.
i've tried nil or [] in irb , []. question if know why working different in rails?
p.s.: gem i'm using cell version 3.3.3.
thanks!
the idiom session[:value] || [], using ||, not or. can try session[:value].to_a. works because nil.to_a becomes [].
Comments
Post a Comment