title: Rails Checkboxes as array
body: <p>I'm trying to pass multiple checkboxes as array to a db table.
  So i want to add multiple topics to a project.</p>
  
  <pre><code>= form_for @project, url: admin_projects_path, :html =&gt; { :multipart =&gt; true } do |p|
    %p
      =p.label :name
      =p.text_field :name 
    %p
      = p.label :topic
    %p
      = p.label "Value1"
      = p.check_box(:topic, {:multiple =&gt; true}, "value1", nil)
      = p.label "Value2"
      = p.check_box(:topic, {:multiple =&gt; true}, "value2", nil)
      = p.label "Value3"
      = p.check_box(:topic, {:multiple =&gt; true}, "value3", nil)
    %p
      = p.submit
  </code></pre>
  
  <p>but here topic returns nil in the projects, even whenever i check multiple checkboxes
  (i added to the whitelist params in the controller, so that cant be the cause)</p>
  
  <p>What am i doing wrong here?</p>
  
  <p>EDIT: </p>
  
  <p>This is the code of the controller:</p>
  
  <pre><code>def new
    @project = Project.new
  end
  
  def create
    @project = Project.new(project_params)
  
    if @project.save
      redirect_to admin_projects_path
    else
      render :new
    end
  end
  
  private
  # param white listing
  
  def project_params
    params.require(:project).permit(:name, :description, :photo, :project_type, :highlight, :content, :topic, :category)
  end
  </code></pre>
  
  <p><strong>Solution found:</strong></p>
  
  <p>View was correctly.</p>
  
  <pre><code> serialize :topic
  </code></pre>
  
  <p>needed be added to the project model</p>
  
  <p>and the permit params should be edited so they only accept arrays on topic </p>
  
  <pre><code>private
  # param white listing
  
  def project_params
    params[:project][:topic] ||= []
    params.require(:project).permit(:name, :description, :content, topic: [])
  end
  </code></pre>