I have a form which is shared among some controllers. Sometimes I pass in isbn argument, sometimes not.
= form_for book do |f|
- if isbn.present?
= f.hidden_field :virtual_isbn_id, :value => isbn.id
How do I check if isbn is populated or not? Alternatively, how can I set isbn to be nil by default?
Thank you.
Use
if defined? isbn .... You should take a look at this Question for example usage: Checking if a variable is defined?Alternatively you can use
isbn.blank?orisbn.nil?to check if the value is nil or blank (e.g. an empty string) if you know that the variable is present.