ruby on rails - Whenever X is true do X, otherwise Y -



ruby on rails - Whenever X is true do X, otherwise Y -

think i'm brain dead. need concise way of writing when x exists (the value specified key in hash), print value (i.e., x), otherwise, print 0. reason needs concise because i'm using in options form_tag, , i'd avoid writing method.

can't think through... here's i've tried:

this won't work because homecoming "0": <%= number_field_tag "transaction[][#{thing}]", :quantity, min: 0, placeholder: 0 || @transactionparams["#{thing}"] %>

this won't work because whenever @transactionparams doesn't exist, instead of getting 0, error undefined method []' nil:nilclass<%= number_field_tag "transaction[][#{thing}]", :quantity, min: 0, placeholder: @transactionparams["#{thing}"] %>`

how ternary operator?

@transactionparams = {:thing => "foo"} puts @transactionparams ? @transactionparams[:thing] : 0 @transactionparams = nil puts @transactionparams ? @transactionparams[:thing] : 0

ruby-on-rails ruby hash operators comparator

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -