title: Create Nested Object with Rails 4 (JSON call)
body: <p>I am refactoring a project, and I remembered that I had some troubles in realizing how to put a nested object, but I found <a href="https://stackoverflow.com/questions/845366/nested-object-creation-with-json-in-rails">this</a> question useful.</p>
  
  <p>So, as I understand it, you needed to pass as a parameter your associated model name in plural and add a '_attributes' to it. It worked great in Rails 3.2.13.</p>
  
  <p>Now, here is what I have in Rails 4:</p>
  
  <pre><code>    class TripsController &lt; Api::V1::ApiController
        def create
          begin
            @user = User.find(params[:user_id])
            begin
              @campaign = @user.campaigns.find(params[:campaign_id])
              if @trip = @campaign.trips.create(trip_params)
                render json: @trip, :include =&gt; :events, :status =&gt; :ok
              else
                render json: { :errors =&gt; @trip.errors }, :status =&gt; :unprocessable_entity
              end
            rescue ActiveRecord::RecordNotFound
              render json: '', :status =&gt; :not_found 
            end
          rescue ActiveRecord::RecordNotFound
            render json: '', :status =&gt; :not_found 
          end
        end
  
        private
  
        def trip_params
          params.require(:trip).permit(:evnt_acc_red, :distance, events_attributes: [:event_type_id, :event_level_id, :start_at, :distance])
        end
      end
  </code></pre>
  
  <p>And the Trip model looks like this:</p>
  
  <pre><code>class Trip &lt; ActiveRecord::Base
  
    has_many :events
    belongs_to :campaign
    accepts_nested_attributes_for :events
  end
  </code></pre>
  
  <p>So, I am doing a POST call with the following JSON:</p>
  
  <pre><code>{"trip":{"evnt_acc_red":3, "distance":400}, "events_attributes":[{"distance":300}, {"distance":400}]}
  </code></pre>
  
  <p>And, even though I don't get any kind of error, no event is being created. The trip is being created correctly, but not the nested object.</p>
  
  <p>Any thoughts on what should I do to make this work on Rails 4?</p>