Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的file.json.erb我想创造像 " 20 mg", "30 mg", 等等这样的价值观......
file.json.erb
20 mg"
"30 mg"
我写了这样的东西,但这是不正确的
<%=(rand() * 50).to_i %> + " mg"
你不需要+,你可以直接构建字符串。尝试这个:
+
"<%=(rand() * 50).to_i %> mg"
几乎正确,试试
<%= (rand() * 50).to_i.to_s + " mg" %>
您也可以使用字符串插值。
<%= "#{(rand() * 50).to_i.to_s} mg" %>