I have this script which is used to append:
function append_place(type) {
var shop_type = type;
$("#shop_type").append(shop_type);
}
Then in my view.html.erb:
<div id="shop_type"></div>
where and type is the data in my Rails database column.
When type has the value cafe and the output of the HTML is:
<div id="shop_type">Cafe</div>
When type has no value, the output of the HTML is:
<div id="shop_type"></div>
I want Javascript to insert Not available when type has no value:
<div id="shop_type">Not available</div>
How do I do that? I can’t use the normal if-else for Rails because the value is delivered via JSON.
Thanks.
Try something like this: