title: Rails - Strong params, and creating a new resource via nested attributes for a delegated association?
body: <p>My Rails 4 app is a fundraising tool for a bike ride. A user can create a RiderReg(istration), and a User also has an associated MailingAddress, that is delegated to the User via the RiderReg. </p>
  
  <p>The associations seem to work in the console, but I'm getting thrown by strong params, and the controller won't accept nested attributes for a RiderReg's MailingAddress -- because the MailingAddress is associated with the User. </p>
  
  <p>You may wonder - Why are Users and Riders separate models? Because Users can be donors and/or riders -- but all users whether riders or no will need addresses.</p>
  
  <p>ANYHOO -- let me add some code examples.</p>
  
  <pre><code>class RiderReg &lt; ActiveRecord::Base
  
      belongs_to :rider, :class_name =&gt; "User"
      delegate :first_name, :last_name, :title, :full_name, :receipts, :mailing_address, to: :rider, allow_nil: true, prefix: false
  
  
    # accepts_nested throws an error - but how else to allow for strong params?
    accepts_nested_attributes_for :mailing_address
  end
  
   class User &lt; ActiveRecord::Base
    has_one :rider_reg, :foreign_key =&gt; :rider_id
  
    has_one :mailing_address, :as =&gt; :addressable
    accepts_nested_attributes_for :mailing_address
  end
  
  class RiderRegsController &lt; ApplicationController
      private 
  
      def rider_reg_params
      params.require(:rider_reg).permit(:ride_option, :primary_phone, :secondary_phone, :birthdate, :goal, :bio, :accept_terms, :photo, :mailing_address_attributes =&gt; [:line1, :line2, :city, :state, :zip])
    end
  end
  </code></pre>
  
  <p>My Params hash submit via form_helper looks like this:</p>
  
  <pre><code>Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"PbDQe/f4S+dlhroY+ZDVh6MS0Mmo0fUr88UiE4OJJQQ=", "rider_reg"=&gt;{"ride_option"=&gt;"Original Track", "mailing_address"=&gt;{"line1"=&gt;"asdfasfd", "line2"=&gt;"", "city"=&gt;"asdfsadf", "state"=&gt;"Alaska", "zip"=&gt;""}, "primary_phone"=&gt;"", "secondary_phone"=&gt;"", "bio"=&gt;"", "goal"=&gt;"0.0"}, "rider_reg_month"=&gt;"1", "rider_reg_year"=&gt;"1934", "rider_reg_day"=&gt;"1", "commit"=&gt;"Create Rider reg"}
  </code></pre>
  
  <p>and my server log tells me this:</p>
  
  <pre><code>Unpermitted parameters: mailing_address
  </code></pre>
  
  <p>So -- after a couple of days of headbanging - I think it may be time to admit my ignorance here. Any advice is much appreciated!
  thanks!</p>