Reputation: 582
I have a form, in which I can set various client fields like client name client address and more.
Only the client name is a must field, and all the other fields can be empty.
After saving the client data I display to the end user the clients details page (with all the clients information).
Now if the address field is empty I want to display some customized text for example "The Address is not set".
Currently my "show" page display only this
Upvotes: 2
Views: 1313
Reputation: 23450
<%=h @client.address.present? && @client.address || "The Address is not set"%>
If you're using it often enough, you may consider making this a helper.
Upvotes: 5
Reputation: 14913
Lots of ways, here's a somewhat messy one
<%=h (@client.address.blank? ? "The Address is not set" : @client.address) %>
Upvotes: 2
Reputation: 4051
Try this…
<%- if @client.address.blank? %>
"The Address is not set"
<%- else %>
<%=h @client.address %>
<%- end %>
Upvotes: 1