I'm digging through some interesting code which I'm convinced is wrong. I wondered whether anyone had a thought as to the syntax the developer was trying to use?
Heres' the bogus code:
render :nothing => true and return if params[:name].nil?
My naive fix alludes to my programming language background:
if params[:name].nil?
render :nothing => true, :status => 404
return
end
Is there a more elegant, more ruby-like way? (semicolons don't count :)
Because in Ruby Operator Precedence, if
has lower precedence than and
, this works exactly as it reads, and is in fact quite common in a lot of rails code that I have seen.
Simple:
return render(:nothing => true) unless params[:name]
But, better:
return render(:nothing => true) if params[:name].blank?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With