Rails single line if else statement
ruby-on-rails, ruby-on-rails-4
Solution
To make it even clearer, you can use logical `OR` and `ActiveSupport's` `Object#presence` (to put `collection.name` only if it exists and isn't blank):
<%= collection.name.presence || @miniature.name %>
If you want to display `collection.name` if it's not `nil`, but it's blank (empty string or string containing only whitespace), it will be enough to have:
<%= collection.name || @miniature.name %>
Problem
I'm trying to write a single line if else statement in a view. ``` <%= collection.name ? collection.name : @miniature.name %> ``` I want it to put collection.name if one exists, otherwise I want it to put @miniature.name