How do I do something like this?
if params[:property] == nil 
 @item.property = true
else 
 @item.property = false
Always forget the proper syntax to write it in one line.
In PHP it would be like this:
@item.property=(params[:property]==nil)true:false
Is it the same in rails?
use the ternary operator:
@item.property = params[:property] ? true : false
or force a boolean conversion ("not not" operation) :
@item.property = !!params[:property]
note : in ruby, it is a common idiom not to use true booleans, as any object other than false or nil evaluates to true.
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