So I'm using Prawn PDF gem for my rails application and I'm trying to write a helper method for part of a text string to be black when the rest of the string is blue, the reason I'm trying to write a helper is because this will be used for many different fields. Not sure if Prawn supports this but I've been giving it a shot.
所以我在我的rails应用程序中使用Prawn PDF gem而我正在尝试编写一个帮助方法,当字符串的其余部分为蓝色时,部分文本字符串为黑色,我试图编写帮助程序的原因是因为这将用于许多不同的领域。不确定Prawn是否支持这个,但我一直在试一试。
text string
文字字符串
pad_bottom(5) { text "Owner: #{inline_black_helper(@order.first.owner)}", align: :center, inline_format: true, color: blue, size: 16 }
inline_black_helper
inline_black_helper
def inline_black_helper(text)
"<color rbg='000000'>#{text}</color>"
end
Aka the same as doing
阿卡和做的一样
pad_bottom(5) { text "Owner: <color rbg='000000'>#{@order.first.owner}</color>", align: :center, inline_format: true, color: blue, size: 16 }
Obviously the last example works fine but as stated, since this will be used for many fields, having to write <color rbg='000000'>..</color>
50 times seems very 'un-rails' to me. This current implementation doesn't raise and error and the actual information is interpolating correctly but the entire text
is blue instead of the first part being blue and the desired @order.first.owner
being black. Any insight is appreciated as always, thanks!
显然,最后一个例子工作得很好,但正如所述,因为这将用于许多领域,不得不写
1 个解决方案
#1
1
Your helper is wrong. You need:
你的助手错了。你需要:
<color rbg='000000'>
You currently have rbg
你现在有rbg
#1
1
Your helper is wrong. You need:
你的助手错了。你需要:
<color rbg='000000'>
You currently have rbg
你现在有rbg