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.
开发者_StackOverflow社区@local_var = passed_var ? passed_var : ''
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?
精彩评论