title: Storing array in rails 4
body: <p>i was looking through SO and following several indications but i still stucked on this.</p>
  
  <p>Im trying to store an array in interest_id column.</p>
  
  <p>Here's mi code and the traceback, it seems trying to saving a hash instead an array, the question is why? </p>
  
  <p><strong>migration:</strong></p>
  
  <pre><code>class CreateSearches &lt; ActiveRecord::Migration
    def change
      create_table :searches do |t|
        t.integer :occasion_id
        t.integer :relationship_id
        t.integer :target_id
        t.integer :genre_id
        t.text :interest_id
        t.integer :user_id
  
        t.timestamps null: false
      end
    end
  end
  </code></pre>
  
  <p><strong>model:</strong></p>
  
  <pre><code>class Search &lt; ActiveRecord::Base
    serialize :interest_id, Array
    def search_products
      products = Product.all
      products = Product.joins(:occasion_products).where(:occasion_products =&gt; {:occasion_id =&gt; occasion_id}) if occasion_id.present?
      products = Product.joins(:relationship_products).where(:relationship_products =&gt; {:relationship_id =&gt; relationship_id}) if relationship_id.present?
      products = Product.joins(:genre_products).where(:genre_products =&gt; {:genre_id =&gt; genre_id}) if genre_id.present?
      products = Product.joins(:target_products).where(:target_products =&gt; {:target_id =&gt; target_id}) if target_id.present?
      products = Product.joins(:interest_products).where(:interest_products =&gt; {:interest_id =&gt; interest_id}) if interest_id.present?
      return products
    end
  end
  </code></pre>
  
  <p><strong>controller:</strong></p>
  
  <pre><code>class SearchesController &lt; ApplicationController
    def new
      @search = Search.new
    end
    def create
      @search = Search.create(search_params)
      redirect_to @search
    end
    def show
      @search = Search.find(params[:id])
    end
  
    private   
    def search_params
      params.require(:search).permit(:occasion_id, :relationship_id, :genre_id, :target_id, {:interest_id =&gt; []})
    end
  end
  </code></pre>
  
  <p><strong>traceback:</strong></p>
  
  <pre><code>ActiveRecord::SerializationTypeMismatch in SearchesController#create
  Attribute was supposed to be a Array, but was a Fixnum. -- 0
  Extracted source (around line #6):
  
  4
  5
  6
  7
  8
  9
  
  
  
  
    end
    def create
      @search = Search.create(search_params)
      redirect_to @search
    end
    def show
  
  Rails.root: /Users/emadobao/Sites/rails/personalgifter
  Application Trace | Framework Trace | Full Trace
  
  app/controllers/searches_controller.rb:6:in `create'
  
  Request
  
  Parameters:
  
  {"utf8"=&gt;"✓",
   "authenticity_token"=&gt;"4mS9gQN8g/DWFab+Ecz77o2FTyGIY7/EezzCGXjkbIdmT4srMsixbFDEg25bgdVaOTuIUJRDedcKudYvPCDLgw==",
   "search"=&gt;{"occasion_id"=&gt;"1",
   "relationship_id"=&gt;"1",
   "target_id"=&gt;"1",
   "genre_id"=&gt;"1",
   "interest_id"=&gt;["",
   "2",
   "4"]},
   "commit"=&gt;"Search"}
  
  Toggle session dump
  Toggle env dump
  Response
  
  Headers:
  
  None
  
  x
  &gt;&gt; 
  </code></pre>