I try to complete exercise 8 at the end of chapter 11 in the Michael Hartl Ruby on Rails tutorial. I was able to successfully apply his assistant on the home page by changing this:
<%= feed_item.content %> to this:
<%= wrap(feed_item.content) %>
in the application / views / shared / _feed_item.html.erb
However, when I try to implement the wrap helper in app / views / users / show.html.erb by doing this:
<%= render wrap(@microposts) %>
I get:
undefined method `scan' for #Array:0x00000102e8cc10>
What am I doing wrong?
Here is the code for the wrapper helper:
module MicropostsHelper def wrap(content) sanitize(raw(content.split.map{ |s| wrap_long_string(s) }.join(' '))) end private def wrap_long_string(text, max_width = 30) zero_width_space = "​" regex = /.{1,#{max_width}}/ (text.length < max_width) ? text : text.scan(regex).join(zero_width_space) end end
source share