In the Michael Hartl Ruby on Rails tutorial, how to use the migration assistant in show.html.erb? I get an undefined `scan 'method

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 = "&#8203;" regex = /.{1,#{max_width}}/ (text.length < max_width) ? text : text.scan(regex).join(zero_width_space) end end 
+4
source share
1 answer

The wrap method expects a string; you pass it an array.

It is not possible to actually read a method because of its formatting, but it looks like it just takes one line - you are trying to publish a whole collection of messages. However, you may be able to compile a wrapped version of the message content.

+1
source

All Articles