Question: I have a larger method, part of which I want to use to take array values and insert them into a link. I'm using the method to generate linked fields in the metadata of an app I'm customizing. The full method is below:

```
def get_facet_from_datastream(resource, datastream_name, field_key, opts={})
  if opts.has_key?(:values)
    values = opts[:values]
  if values.nil? then values = [opts.fetch(:default, "")] end
  else
    values = resource.get_values_from_datastream(datastream_name, field_key, opts.fetch(:default, ""))
  if values.empty? then values = [ opts.fetch(:default, "") ] end
 end

 facet = field_key.to_a.join("_") + "_facet"

 values.each do |v|
   searchv = v.to_s.gsub(/ /, "+")
   link =  "<a href=\"http://development4/lcdl/catalog?f[#{facet}][]=#{searchv}\">#{v}</a>"
   return link.html_safe
 end

end

```

I'm having problems in the "`values.each do`" section. Returning the link works on the first value in the array, but halts at that. What I'd ideally like is each link followed by a line break, but I'm clearly muddling the syntax.

I hope this makes sense.

Answer: 
Yes, it stops, because you have `return link.html_safe` in your `each` block. It returns first value of `values` array.

Update your code part:

```
 values.map do |v|
   searchv = v.to_s.gsub(/ /, "+")
   "<a href=\"http://development4/lcdl/catalog?f[#{facet}][]=#{searchv}\">#{v}</a>"
 end.join.html_safe

```
You have a `return` statement in your each loop. This will exit the method, returning on the first pass.

You might want to do something like this instead:

```
values.map do |v|
  searchv = v.to_s.gsub(/ /, "+")
  link =  "<a href=\"http://development4/lcdl/catalog?f[#{facet}][]=#{searchv}\">#{v}</a>"
  link.html_safe
end.join

```