Rails single line if else statement

后端 未结 3 652
野性不改
野性不改 2020-12-31 04:41

I\'m trying to write a single line if else statement in a view.

<%= collection.name ? collection.name : @miniature.name %>

I want it

3条回答
  •  心在旅途
    2020-12-31 05:08

    Check for the presence of collection.name first.

    <%= collection.name.present? ? collection.name : @miniature.name %>
    

提交回复
热议问题