简体   繁体   English

尝试在新行中显示字符串拆分时出现错误-Ruby on Rails

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM