开发者

Set variable to ternary

开发者 https://www.devze.com 2023-03-27 09:51 出处:网络
I\'m trying to render a partial within a view. When calling the render I\'m passing :locals correctly. However, when trying to set the local variable in the partial view to a ternary, the \'else\' log

I'm trying to render a partial within a view. When calling the render I'm passing :locals correctly. However, when trying to set the local variable in the partial view to a ternary, the 'else' logic of the statement does not get passed.

@local_var = passed_var ? passed_var : ''

开发者_StackOverflow社区

The ||= operator will not work in this instance for what I'm trying to achieve.

@local_var = 'wrapping_text_open' + passed_var + 'wrapping_text_close' ||= ''


I never use this, but you could do

local_var = (defined? passed_var) ? passed_var : ""

local_var = (defined? passed_var) ? 'wrapping_text_open' + passed_var + 'wrapping_text_close' : ''

Why use an instance variable?

0

精彩评论

暂无评论...
验证码 换一张
取 消