Ctpelnar1988 Ctpelnar1988 - 1 year ago 74
Ruby Question

How to get rid of array after .map method

I am instantiating a variable like so:

Searches Controller:

@search_results = Business.near(params[:search_zip], params[:radius]).to_a

Searches View

<%= @search_results.map do |sr| %>
<%= sr.business_name %>
<% end %>

=> PetStore FoodStore BeautyStore ClothingStore ["\n", "\n", "\n", "\n"]`

How can I get rid of the array at the end?

Answer Source

You should change from .map to .each since you aren't trying to change the value of the array. You should be able to fix with this:

<% @search_results.each do |sr| %>
  <%= sr.business_name %>
<% end %>

The <%= means you want to print the value

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download