title: Rails Nested form inserts nulls
body: <p>I'm in Rails 3.2.6</p>
  
  <p>We have a nested form that was functioning up until recently (not entirely certain when the error started occurring).  Now the queries are passing in nulls.</p>
  
  <p>Example output:</p>
  
  <pre><code>Started POST "/articles" for 127.0.0.1 at 2012-07-12 11:04:16 -0600
  Processing by ArticlesController#create as HTML
    Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"thing=", "article"=&gt;{"asset_attributes"=&gt;{"name"=&gt;"asdf", "short_desc"=&gt;"asdfasdfsadg", "publish_date"=&gt;"2012-07-12 11:4", "content_section_attributes"=&gt;{"section_id"=&gt;"1", "primary_section"=&gt;"1"}, "section_ids"=&gt;[""], "author_id"=&gt;"", "display_authorbiography"=&gt;"1", "last_modified_by"=&gt;"1", "by_line"=&gt;"", "content_image_attributes"=&gt;{"image_id"=&gt;""}, "keywords_string"=&gt;"", "public_keywords_string"=&gt;"", "meta_public_keywords"=&gt;"", "meta_page_title"=&gt;"", "meta_description"=&gt;"", "meta_url_name"=&gt;"", "guid"=&gt;"", "canonical"=&gt;"", "partner_id"=&gt;"", "tagline"=&gt;"", "series_id"=&gt;"", "display_adsense"=&gt;"1", "sweepstakes"=&gt;""}, "content"=&gt;"&lt;p&gt;asdfasgasg&lt;/p&gt;"}, "img_size"=&gt;"i01", "show_cap"=&gt;"1", "img_pos"=&gt;"left", "commit"=&gt;"Create"}
    User Load (0.2ms)  SELECT `people`.* FROM `people` WHERE `people`.`type` IN ('User') AND `people`.`id` = 1 LIMIT 1 /*application:TmnCoreCms,controller:articles,action:create*/
    Section Load (0.1ms)  SELECT `sections`.* FROM `sections` /*application:TmnCoreCms,controller:articles,action:create*/
    Site Load (0.1ms)  SELECT `sites`.* FROM `sites` WHERE `sites`.`id` IN (1) /*application:TmnCoreCms,controller:articles,action:create*/
    Site Load (0.1ms)  SELECT `sites`.* FROM `sites` /*application:TmnCoreCms,controller:articles,action:create*/
    Section Load (0.1ms)  SELECT `sections`.* FROM `sections` WHERE `sections`.`site_id` IN (1) /*application:TmnCoreCms,controller:articles,action:create*/
    Role Load (0.1ms)  SELECT `roles`.* FROM `roles` INNER JOIN `user_roles` ON `roles`.`id` = `user_roles`.`role_id` WHERE `user_roles`.`user_id` = 1 /*application:TmnCoreCms,controller:articles,action:create*/
     (0.1ms)  BEGIN /*application:TmnCoreCms,controller:articles,action:create*/
     (0.1ms)  COMMIT /*application:TmnCoreCms,controller:articles,action:create*/
     (0.1ms)  BEGIN /*application:TmnCoreCms,controller:articles,action:create*/
     (0.1ms)  COMMIT /*application:TmnCoreCms,controller:articles,action:create*/
     (0.1ms)  BEGIN /*application:TmnCoreCms,controller:articles,action:create*/
    SQL (0.2ms)  INSERT INTO `articles` (`content`, `created_at`, `static_url`, `updated_at`) VALUES ('&lt;p&gt;asdfasgasg&lt;/p&gt;', '2012-07-12 17:04:16', NULL, '2012-07-12 17:04:16') /*application:TmnCoreCms,controller:articles,action:create*/
    Article Load (0.3ms)  SELECT `articles`.* FROM `articles` WHERE `articles`.`id` = 25 LIMIT 1 /*application:TmnCoreCms,controller:articles,action:create*/
  {}
    SQL (0.0ms)  INSERT INTO `assets` (`aasm_state`, `author_id`, `by_line`, `canonical`, `content_id`, `content_type`, `created_at`, `creator_id`, `display_adsense`, `display_authorbiography`, `guid`, `last_modified_by`, `legacyid`, `live_date`, `meta_description`, `meta_page_title`, `meta_public_keywords`, `meta_url_name`, `migration_guid`, `name`, `partner_id`, `publish_date`, `publish_version`, `series_id`, `short_desc`, `sweepstakes`, `tagline`, `updated_at`, `url_name`) VALUES ('new', NULL, NULL, NULL, 25, 'Article', '2012-07-12 17:04:16', NULL, 1, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2012-07-12 17:04:16', NULL) /*application:TmnCoreCms,controller:articles,action:create*/
    SQL (0.2ms)  INSERT INTO `content_sections` (`content_id`, `content_type`, `created_at`, `primary_section`, `section_id`, `updated_at`) VALUES (53, 'Asset', '2012-07-12 17:04:16', 1, NULL, '2012-07-12 17:04:16') /*application:TmnCoreCms,controller:articles,action:create*/
     (33.6ms)  COMMIT /*application:TmnCoreCms,controller:articles,action:create*/
  Redirected to http://localhost:3000/articles/53-
  Completed 302 Found in 63ms (ActiveRecord: 35.3ms)
  </code></pre>
  
  <p>So as you can see the attributes are being sent.  Our controller looks like this.</p>
  
  <pre><code>def new
      @article = Article.new
      @asset = @article.build_asset
    end
  
    def create
      @article = Article.new(params[:article])
      if @article.save
        flash[:notice] = 'Article was successfully created.'
        redirect_to @article
      else
        render :action =&gt; "new"
      end
    end
  </code></pre>
  
  <p>Relevant Model information:</p>
  
  <pre><code>class ContentType &lt; ActiveRecord::Base
    self.abstract_class = true
    validates_presence_of :asset, :message =&gt; "Must have an asset"
    has_one :asset, :as =&gt; :content, :dependent =&gt; :destroy
    delegate :name, :url_name, :author, :creator, :publish_date, :short_desc,
             :aasm_state, :live_date, :keywords,
             :to =&gt; :asset, :allow_nil =&gt; true
    delegate :keywords_string, :public_keywords_string,
             :to =&gt; :asset,
             :allow_nil =&gt; true
  
    def initialize(*args)
      super(*args)
    end
  
  
    def to_param
      "#{asset.id}-#{url_name}"
    end
  end
  
  class Asset &lt; ActiveRecord::Base
    include AASM
    include Keywordable
    attr_accessible :author_id,
                    :by_line,
                    :canonical,
                    :content_image_attributes,
                    :content_section_attributes,
                    :creator_id,
                    :display_adsense,
                    :display_authorbiography,
                    :guid,
                    :keywords,
                    :keywords_string,
                    :last_modified_by,
                    :meta_description,
                    :meta_page_title,
                    :meta_public_keywords,
                    :meta_url_name,
                    :name,
                    :partner_id,
                    :public_keywords_string,
                    :publish_date,
                    :related_content_attributes,
                    :section_ids,
                    :series_id,
                    :short_desc,
                    :sweepstakes,
                    :syndication_partner_ids,
                    :tagline,
                    :url_name
  
    belongs_to :author,  :class_name =&gt; 'Person'
    belongs_to :content, :polymorphic =&gt; true
    has_many :content_sections, :as =&gt; :content,  :conditions =&gt; {:primary_section =&gt; nil},  :dependent =&gt; :destroy
  
  class Article &lt; ContentType
    attr_accessible :images_attributes,
                    :content_images_attributes,
                    :content_text,
                    :content,
                    :asset_attributes,
                    :content_attributes
  </code></pre>
  
  <p>I really dislike this association set up but it is what it is.  What's happening is that the nested form</p>
  
  <pre><code>&lt;%= f.fields_for :asset do |asset| %&gt;
      &lt;fieldset class="span8"&gt;
          &lt;legend&gt;Asset Description&lt;/legend&gt;
          &lt;div id='a_title'&gt;
              &lt;%= asset.label :name, "Title &lt;span class='req'&gt;*&lt;/span&gt;".html_safe %&gt;
              &lt;%= asset.text_field :name, :class =&gt; 'asset_textarea counter', "data-max" =&gt; 255 %&gt;
              &lt;br/&gt;&lt;span&gt;&lt;/span&gt;
          &lt;/div&gt;
          &lt;div id='a_desc'&gt;
              &lt;%= asset.label :short_desc, "Teaser&lt;span class='req'&gt;*&lt;/span&gt;".html_safe %&gt;
                      &lt;%= asset.text_area :short_desc, :class =&gt; "span7 asset_textarea counter", "data-max" =&gt; 255, :rows =&gt; 7 %&gt;
                      &lt;br/&gt;&lt;span&gt;&lt;/span&gt;
          &lt;/div&gt;
      &lt;/fieldset&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Is somehow passing the fields and Rails is putting nulls in.  I have no attr_accessible warnings.  If I do an update on the article it will save the asset data.  So something is going wrong on the initialization I think but I'm not sure what.</p>
  
  <p><strong>TLDR</strong>
  Rails is not passing values into sql query despite attr_accessible having the nested attributes.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>The contentTypesController has some before filters that I originally thought were the issue (they still may be I'm still figuring out how they are being used)</p>
  
  <pre><code>class ContentTypesController &lt; ApplicationController
  
    before_filter :clean_syndication_partners, :only =&gt; [:update]
    before_filter :setup_existing_content_instance_variable, :except =&gt; [:index, :new, :create, :sort, :update_json, :vid_search, :search_library]
    #before_filter :setup_new_content_instance_variable, :only =&gt; [:new, :create]
    before_filter :get_sections
    before_filter :get_sites
    def clean_syndication_partners
      @asset = Asset.find(params[:id], :include =&gt; :content)
      @asset.syndication_partners = []
    end
  
    def get_sites
      @sites_all = Site.all(:include =&gt; :sections)
    end
    def get_sections
      @sections = Section.all(:include =&gt; :site)
    end
  
    def setup_existing_content_instance_variable
      @asset = Asset.find(params[:id], :include =&gt; :content) if @asset.nil?
      instance_variable_set("@#{@asset.content.class.name.underscore}", @asset.content)
    end
  
    # def setup_new_content_instance_variable
    #   pub_keyword = false
    #   current_class = self.controller_name.singularize
    #   @content_type = current_class.downcase
    #   if params[current_class]
    #     cur_content= current_class.camelize.constantize.new(params[current_class])
    #     #cur_content.asset = Asset.update_attributes(params[current_class][:asset_attributes])
    #   else
    #     cur_content= current_class.camelize.constantize.new
    #     #cur_content.asset=Asset.new
    #   end
    #   #cur_content.asset.creator=current_user
    #   #instance_variable_set(:@asset, cur_content.asset)
    #   instance_variable_set("@#{current_class}", cur_content)
    # end
  
  end
  </code></pre>