开发者

Set variable to ternary

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜