title: Rails 4.2 : Form with multiple models - param is missing or the value
body: <p>I'm having trouble with Rails 4.2 to create a form with multiple models.
  I'm creating a form to allow a user to order a gift card with a custom stripe payment form all in one.
  I tried different ways using form_tag instead of simple_form_for and simple_fields_for and I tried all the solution provided on this website but I can't find a way out of this hell!</p>
  
  <p>My form is the following :</p>
  
  <pre><code>     =simple_form_for @giftcard, url: gift_cards_path, html: {"accept-charset" =&gt; "UTF-8", :autocomplete =&gt; "off", :enctype =&gt; "multipart/form-data", :method =&gt; "post" } do |f|
  
        (...)
  
        = field_set_tag 'Delivery mode' do
          .form-row
            = f.label :delivery_mode, 'She receive the mail'
            = f.radio_button :delivery_mode, 'email_to_recipient'
            = f.label :delivery_mode, 'I receive the mail'
            = f.radio_button :delivery_mode, 'email_to_giver'
            = f.label :delivery_mode, 'Delivery with in box with a jewel'
            = f.radio_button :delivery_mode, 'gift_box', id: 'gift_box'
  
        = field_set_tag 'Who is the gift for ?' do
          .form-row
            = f.input :recipient_first_name, label: 'First Name'
          .form-row
            = f.input :recipient_last_name, label: 'Last Name'
          .form-row
            = f.input :recipient_email, placeholder: 'example@mail.com', label: 'Son adresse email'
          .form-row
            = f.input :message, placeholder: 'Your message', label: 'Son message'
  
        = f.simple_fields_for :payment do |p|
         .form-row
           = p.input :card_number, label: 'Numéro de carte'
         .form-row
           = p.input :card_cvc, input_html: { "size" =&gt; 4, "data-stripe" =&gt; "cvv" }, label: 'CVV'
         .form-row
           = p.input :card_expiration_month, input_html: { "placeholder" =&gt; "MM", "size" =&gt; 2, "data-stripe" =&gt; "exp-month" }
           = p.input :card_expiration_year, input_html: { "placeholder" =&gt; "YYYY", "size" =&gt; 4, "data-stripe" =&gt; "exp-year" }
  
       .form-row
         = f.button :submit, 'Send your gift !'
  </code></pre>
  
  <p>My controller is the following :</p>
  
  <pre><code>def new
     @giftcard = GiftCard.new
     @payment = Payment.new
  end
  
  def create
      @giftcard = GiftCard.new(giftcard_params)
      @payment = Payment.new(creditcard_params)
      @giftcard.amount += 9.90 if @giftcard.gift_box?
      respond_to do |format|
        if @giftcard.save &amp;&amp; @payment.process_payment
          code_coupon = CodeCoupon.create(name: giftcard.coupon, value: 0, category: 'membership', origin: 'gift')
          if giftcard.delivery_mode == 'gift_box'
            UserMailer.prepare_gift_box(@giftcard)
            UserMailer.giftcard_recipe(@giftcard)
          elsif @giftcard.delivery_mode == 'email_to_giver'
            UserMailer.send_gift_card(@giftcard, @giftcard.giver_email)
            UserMailer.giftcard_recipe(@giftcard)
          elsif @giftcard.delivery_mode == 'email_to_recipient'
            UserMailer.send_gift_card(@giftcard, @giftcard.recipient_email)
            UserMailer.giftcard_recipe(@giftcard)
          end
  
          format.html { redirect_to @giftcard, notice: 'Votre carte cadeau à bien été créée et vous a été envoyé par email' }
          format.json { render :show, status: :created, location: @giftcard }
        else
          format.html { render :new, locals: { errors: @giftcard.errors.full_messages } }
          format.json { render json: @giftcard.errors, status: :unprocessable_entity }
        end
      end
  end
  
  private
  
    def giftcard_params
      params.require(:gift_card).permit(:recipient_email, :recipient_first_name, :recipient_last_name, :giver_email, :giver_phone, :giver_first_name, :giver_last_name, :message, :amount, :delivery_mode, :delivery_first_name, :delivery_last_name, :delivery_street, :delivery_city, :delivery_zip)
    end
  
    def creditcard_params
      params.require(:payment).permit(:card_number, :card_cvc, :card_expiration_month, :card_expiration_year, :card_token )
    end
  </code></pre>
  
  <p>And the troubled model:</p>
  
  <pre><code>class Payment
    include ActiveModel::Model
  
    attr_accessor :card_number, :card_cvc, :card_expiration_month, :card_expiration_year, :card_token
  
    validates :card_number, presence: true
    validates :card_cvc, presence: true
    validates :card_expiration_month, presence: true
    validates :card_expiration_year, presence: true
  
    def payment_process
      Stripe::Charge.create(
        amount: amount * 100,
        description: "paiement unique",
        source: card_token,
        currency: 'eur'
      )
    end
  end
  </code></pre>
  
  <p>When I try to validate the form, it returns the following error :
  ActionController::ParameterMissing - param is missing or the value is empty: payment:
   actionpack (4.2.8) lib/action_controller/metal/strong_parameters.rb:251:in <code>require'
   app/controllers/gift_cards_controller.rb:56:in</code>creditcard_params'
   app/controllers/gift_cards_controller.rb:13:in `create'</p>
  
  <p>If I remove the require in the creditcard_params method and I click on submit, I get in the log :
  Unpermitted parameter: payment
  Unpermitted parameters: utf8, authenticity_token, gift_card, commit
     (0.1ms)  BEGIN
     (0.2ms)  ROLLBACK</p>
  
  <p><strong>EDIT</strong> </p>
  
  <p>Here the parameters that I receive in the log :</p>
  
  <pre><code>    Started POST "/gift_cards" for ::1 at 2017-10-06 10:17:42 +0200
      Processing by GiftCardsController#create as HTML
        Parameters: {
  "utf8"=&gt;"✓", 
  "authenticity_token"=&gt;"UB1keTN7YNDhaEBdIT6cYf/qrwr/QxCpFEYwvGDBLWmYvZiVjXxFg+bQ9vaPAfQTx32d/D7jHnShsTmsqMwLrA==", 
  "gift_card"=&gt;{
    "recipient_first_name"=&gt;"", 
    "recipient_last_name"=&gt;"", 
    "recipient_email"=&gt;"", 
    "message"=&gt;"", 
    "giver_first_name"=&gt;"", 
    "giver_last_name"=&gt;"", 
    "giver_email"=&gt;"", 
    "giver_phone"=&gt;"", 
    "delivery_first_name"=&gt;"", 
    "delivery_last_name"=&gt;"", 
    "delivery_street"=&gt;"", 
    "delivery_city"=&gt;"", 
    "delivery_zip"=&gt;"", 
    "payment"=&gt;{
       "card_number"=&gt;"", 
       "card_cvc"=&gt;"", 
       "card_expiration_month"=&gt;"", 
       "card_expiration_year"=&gt;""
       }
    }, 
    "commit"=&gt;"Send your gift !"
  }
  </code></pre>
  
  <p>Thank you in advance for your help,</p>
  
  <p>Regards</p>