[英]Getting error trying to display string split on new lines - Ruby on Rails
I have the following code: 我有以下代码:
<% @recipe.instructions.each do |instruction| %>
<li><%= instruction %></li>
<% end %>
I get the following error: undefined method 'each' for #<String:0xa354eb8>
我收到以下错误:
#<String:0xa354eb8>
未定义方法'each'
@recipe.instructions is defined as text @ recipe.instructions定义为文本
Please help! 请帮忙!
Reese 里斯
Use each_line
instead of each
. 使用
each_line
而不是each
。 String#each
has been removed in ruby 1.9, each_line
works with all ruby versions. String#each
已在ruby 1.9中删除, each_line
适用于所有ruby版本。
What about String#each_line
? 那么
String#each_line
呢? It should work with both Ruby 1.8 and 1.9. 它应该与Ruby 1.8和1.9一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.