title: ActiveRecord::NotNullViolation (PG::NotNullViolation: ERROR: null value in column "content_id" violates not-null constraint
body: <p>I'm currently building a rails 5 application in which a <code>shout</code> can be a <code>TextShout</code> or a <code>PhotoShout</code>. When creating a shout, <code>content_id</code> is not being pass in the params therefore raising a Not Null Value error. In the migration for the shout I can not find where the error is coming from. I have the following files.</p>
  
  <p>show.html.erb</p>
  
  <pre><code>&lt;%= form_for @shout do |form| %&gt;
  &lt;%= form.hidden_field :content_type, value: "TextShout" %&gt;
    &lt;%= form.fields_for :content do |content_form| %&gt;
      &lt;%= content_form.text_field :body, placeholder: "shout here!", required: true %&gt;
      &lt;%= content_form.submit "Shout!" %&gt;
      &lt;% end %&gt;
  &lt;% end %&gt;
  
  &lt;%= form_for @shout do |form| %&gt;
  &lt;%= form.hidden_field :content_type, value: "PhotoShout" %&gt;
    &lt;%= form.fields_for :content do |content_form| %&gt;
      &lt;%= content_form.file_field :image, required: true %&gt;
      &lt;%= content_form.submit "Shout!" %&gt;
      &lt;% end %&gt;
  &lt;% end %&gt;
  
  &lt;%= render @shouts %&gt;
  </code></pre>
  
  <p>migration/_make_shouts_polymorphic.rb</p>
  
  <pre><code>class MakeShoutsPolymorphic &lt; ActiveRecord::Migration[5.1]
    class Shout &lt; ApplicationRecord
      belongs_to :content, polymorphic: true
    end
    class TextShout &lt; ApplicationRecord; end
    def change
      change_table(:shouts) do |t|
        t.string :content_type
        t.integer :content_id
        t.index [:content_type, :content_id]
      end
  
      reversible do |dir|
        Shout.reset_column_information
        Shout.find_each do |shout|
          dir.up do
            text_shout = TextShout.create(body: shout.body)
            shout.update(content_id: text_shout.id, content_type: "TextShout")
          end
          dir.down do
            shout.update(body: shout.content.body)
            shout.content.destroy 
          end
        end
      end
  
      remove_column :shouts, :body, :string
    end
  end
  </code></pre>
  
  <p>shouts_controller.rb</p>
  
  <pre><code>class ShoutsController &lt; ApplicationController
  
    def show
      @shout = Shout.find(params[:id])
    end
  
    def create
      shout = current_user.shouts.create(shout_params)
      redirect_to root_path, redirect_options_for(shout)
    end
  
    private
  
    def shout_params
      { content: content_from_params }
    end
  
    def content_from_params
      case params[:shout][:content_type]
      when "TextShout" then TextShout.new(text_shout_content_params)
      when "PhotoShout" then PhotoShout.new(photo_shout_content_params)
      end
    end
  
    def text_shout_content_params
      params.require(:shout).require(:content).permit(:body)
    end
  
    def photo_shout_content_params
      params.require(:shout).require(:content).permit(:image)
    end
  
    def redirect_options_for(shout)
      if shout.persisted?
        {notice: "Shouted Successfully"}
      else
        {alert: "Could not shout"}
      end
    end
  end
  </code></pre>