Search code examples
ruby-on-railsrubyruby-on-rails-5erbruby-on-rails-6

Remove array from showing under my rails erb-form


I have a checkbox form where you can select many customers to attend a single event. The form works but there is an array of all customers under it and I can't figure out how to remove it.

events.rb

def addcustomer
    @event = Event.find(params[:id])
    @customer = Customer.all
  end

routes.rb

resources :events do
    get  'addcustomer', on: :member, as: 'add'
  end

addcustomerform.html.erb


<%= form_for(@event) do |f| %>
  <%= hidden_field_tag "event[customer_ids][]", nil%>
  <%= @customer.each do |customer| %>
    <%= check_box_tag "event[customer_ids][]", customer.id,
     @event.customer_ids.include?(customer.id), id:dom_id(customer) %>
    <%= label_tag dom_id(customer), customer.id %>
    <%= label_tag dom_id(customer), customer.name %> --
    <%= label_tag dom_id(customer), customer.email %> --
    <%= label_tag dom_id(customer), customer.phone %>
    <br>
  <% end %>  
  <br>
  <%= f.submit%>
<% end %>  

Here is a photo of what the issue looks like: enter image description here

Here is the repo https://github.com/robbiesoho/fanfactory

I hope someone can help. Thank you


Solution

  • it is not the params that are shown there but all the customers. If you replace <%= @customer.each do |customer| %> with <% @customer.each do |customer| %>

    The difference is that I remove the =. The = means that the line should be added to the HTML as text. on that line is the @customer array, and the result f @customer.to_s is what you see there.

    For more information, please read: What is the difference between <%, <%=, <%# and -%> in ERB in Rails?