title: Rails 4 - nested forms with Cocoon gem
body: <p>I am trying to make an app in Rails 4.</p>
  
  <p>I use simple form with Cocoon gem.</p>
  
  <p>In development mode, I have all of this working correctly, however in production mode its a big mess.</p>
  
  <p>I have profile model and a qualifications model.</p>
  
  <p>The associations are:</p>
  
  <p><strong>profile.rb</strong></p>
  
  <pre><code>has_many :qualifications  
  accepts_nested_attributes_for :qualifications,  reject_if: :all_blank, allow_destroy: true
  </code></pre>
  
  <p><strong>qualification.rb</strong></p>
  
  <pre><code>belongs_to :profile
  </code></pre>
  
  <p>In my profiles new form, I have:</p>
  
  <pre><code>&lt;%= simple_form_for(@profile, multipart: true) do |f| %&gt;
              &lt;%= f.error_notification %&gt;
  
                &lt;div class="form-inputs"&gt;
  
              &lt;div class="intpol2"&gt;
                Your professional qualifications
              &lt;/div&gt;
              &lt;%= f.simple_fields_for :qualifications do |f| %&gt;
  
                &lt;%= render 'qualifications/qualification_fields', f: f %&gt;  
              &lt;% end %&gt;
              &lt;/div&gt;
            &lt;div class="row"&gt;
              &lt;div class="col-md-6"&gt;
  
                 &lt;%= link_to_add_association 'Add a qualification', f, :qualifications, partial: 'qualifications/qualification_fields' %&gt;
  
              &lt;/div&gt;
  
            &lt;/div&gt;
  
            &lt;div class="row"&gt;
  </code></pre>
  
  <p>In my qualifications fields new form, I have:</p>
  
  <pre><code>&lt;div class="nested-fields"&gt;
  &lt;div class="container-fluid"&gt;
  
  
  
            &lt;div class="form-inputs"&gt;
  
  
              &lt;div class="row"&gt;
                  &lt;div class="col-md-6"&gt;
                      &lt;%= f.input :title, :label =&gt; "Your award" %&gt; 
                  &lt;/div&gt;
  
                  &lt;div class="col-md-6"&gt;
  
  
                  &lt;/div&gt;
  
  
              &lt;/div&gt;
  
              &lt;div class="row"&gt;
                  &lt;div class="col-md-6"&gt;
                      &lt;%= f.input :level,   collection: [ "Bachelor's degree", "Master's degree", "Ph.D", "Post Doctoral award"] %&gt;
                  &lt;/div&gt;
  
  
                  &lt;div class="col-md-6"&gt;
                  &lt;%= f.input :year_earned, :label =&gt; "When did you graduate?", collection: (Date.today.year - 50)..(Date.today.year) %&gt;
                  &lt;/div&gt;
  
            &lt;/div&gt;
  
  
            &lt;div class="row"&gt;
                  &lt;div class="col-md-6"&gt;
                      &lt;%= link_to_remove_association 'Remove this qualification', f %&gt;
                  &lt;/div&gt;
  
            &lt;/div&gt;
  
  
            &lt;/div&gt;
  
  &lt;/div&gt;  
  &lt;/div&gt;      
  </code></pre>
  
  <p>In development, when I click the link to add a new qualification, it reloads the profile new form, but does not reveal the qualifications field form. </p>
  
  <p>I have the same setup with address model (same as qualification).</p>
  
  <p>All of this works in development, but not in production.</p>
  
  <p>Is there an extra step required to get this working in production?</p>
  
  <p>My qualifications controller:</p>
  
  <pre><code>class QualificationsController &lt; ApplicationController
    before_action :set_qualification, only: [:show, :edit, :update, :destroy]
    before_action :authenticate_user!
  
    # GET /qualifications
    # GET /qualifications.json
    def index
      @qualifications = Qualification.all
      authorize @qualifications
    end
  
    # GET /qualifications/1
    # GET /qualifications/1.json
    def show
    end
  
    # GET /qualifications/new
    def new
      @qualification = Qualification.new
      authorize @qualification
    end
  
    # GET /qualifications/1/edit
    def edit
    end
  
    # POST /qualifications
    # POST /qualifications.json
    def create
      @qualification = Qualification.new(qualification_params)
      authorize @qualification
  
      respond_to do |format|
        if @qualification.save
          format.html { redirect_to @qualification }
          format.json { render :show, status: :created, location: @qualification }
        else
          format.html { render :new }
          format.json { render json: @qualification.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PATCH/PUT /qualifications/1
    # PATCH/PUT /qualifications/1.json
    def update
      respond_to do |format|
        if @qualification.update(qualification_params)
          format.html { redirect_to @qualification }
          format.json { render :show, status: :ok, location: @qualification }
        else
          format.html { render :edit }
          format.json { render json: @qualification.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # DELETE /qualifications/1
    # DELETE /qualifications/1.json
    def destroy
      @qualification.destroy
      respond_to do |format|
        format.html { redirect_to qualifications_url }
        format.json { head :no_content }
      end
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_qualification
        @qualification = Qualification.find(params[:id])
        authorize @qualification
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def qualification_params
        params[:qualification].permit(:profile_id, :level, :title, :year_earned, :institution)
      end
  end
  </code></pre>
  
  <p>My profiles controller:</p>
  
  <pre><code>class ProfilesController &lt; ApplicationController
    before_action :set_profile, only: [:show, :edit, :update, :destroy]
    before_action :authenticate_user!
    after_action :verify_authorized
  
    # GET /profiles
    # GET /profiles.json
    def index
      @profiles = Profile.all
      authorize @profiles
    end
  
    # GET /profiles/1
    # GET /profiles/1.json
    def show
    end
  
    # GET /profiles/new
    def new
      @profile = Profile.new
      @profile.qualifications.build
      @profile.visions.build
      @profile.personalities.build
      @profile.addresses.build
  
      authorize @profile
    end
  
    # GET /profiles/1/edit
    def edit
    end
  
    # POST /profiles
    # POST /profiles.json
    def create
      @profile = Profile.new(profile_params)
      authorize @profile
  
      respond_to do |format|
        if @profile.save
          format.html { redirect_to @profile }
          format.json { render :show, status: :created, location: @profile }
        else
          format.html { render :new }
          format.json { render json: @profile.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PATCH/PUT /profiles/1
    # PATCH/PUT /profiles/1.json
    def update
      respond_to do |format|
        if @profile.update(profile_params)
          format.html { redirect_to @profile }
          format.json { render :show, status: :ok, location: @profile }
        else
          format.html { render :edit }
          format.json { render json: @profile.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # DELETE /profiles/1
    # DELETE /profiles/1.json
    def destroy
      @profile.destroy
      respond_to do |format|
        format.html { redirect_to profiles_url }
        format.json { head :no_content }
      end
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_profile
        @profile = Profile.find(params[:id])
        authorize @profile
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def profile_params
       params.require(:profile).permit(:user_id, :title, :hero, :overview, :research_interest, :occupation, :external_profile, 
          :working_languages, :tag_list,
            user_attributes: [:avatar],
            personality_attributes: [:average_day, :fantasy_project, :preferred_style],
            vision_attributes: [:long_term, :immediate_challenge], 
            qualifications_attributes: [:id, :level, :title, :year_earned, :institution, :_destroy],
            addresses_attributes: [:id, :unit, :building, :street_number, :street, :city, :region, :zip, :country, :latitude, :longitude, :_destroy] )
      end
  end
  </code></pre>