title: No route matches - missing required keys[:id]
body: <p><strong>Background</strong></p>
  
  <p>I'm implementing a feature in my application that allow users to rate and review pictures. </p>
  
  <p>My problem stems from nesting Reviews resources inside Pictures resources, specifically in my Review#Edit function. The error message specifically declares missing required keys: [:id]</p>
  
  <p><strong>Error Message</strong></p>
  
  <pre><code>ActionController::URLGenerationError in Reviews#Edit
  No route matches {:action=&gt;"show", :controller=&gt;"reviews", :format=&gt;nil, :picture_id=&gt;#&lt;Review id: 4, username: "DarkMouse", body: "Updating review", picture_id: 11, created_at: "2014-08-14 03:26:52", updated_at: "2014-08-14 03:55:29"&gt;, :id=&gt;nil} missing required keys: [:id]
  Undefined method 'reviews_path' for #&lt;#&lt;Class:0x45c1b00&gt;:0x39ae810&gt;
  Extracted source (Around line #7):
  4 &lt;div class = 'center'&gt;
  5   &lt;div class = 'center'&gt;
  6 
  7     &lt;% form_for [:picture, @review] do |f| %&gt;
  8
  9      &lt;p&gt;
  10        &lt;%= f.label :username, :class =&gt; 'marker' %&gt;&lt;br /&gt; 
  </code></pre>
  
  <p>I searched for answers on Stack Overflow.com(My references are given at the bottom) and was advised to do this.</p>
  
  <pre><code>&lt;td&gt;&lt;%= link_to 'Edit', edit_picture_review_path(@picture, review) %&gt;&lt;/td&gt;
  </code></pre>
  
  <p>Every single solution I came across said to edit the path to include the specific object. If this is any indication, it looks like it really should work.</p>
  
  <p><strong>Parameters</strong></p>
  
  <pre><code>{"picture_id"=&gt;"11",
  "id"=&gt;"4"}
  </code></pre>
  
  <p>Also, my path_url is as follows</p>
  
  <pre><code>http://localhost:3000/pictures/11/reviews/4/edit
  </code></pre>
  
  <p>The URL path looks similar to my defined routes as well</p>
  
  <pre><code>edit_picture_review_path GET   /pictures/:picture_id/reviews/:id/edit(.:format) reviews#edit
  </code></pre>
  
  <p>I am using a Posts/Comments relationship model for a Pictures/Reviews relationship.</p>
  
  <p><strong>Models</strong></p>
  
  <pre><code>class Review &lt; ActiveRecord::Base
    belongs_to :picture
  end
  
  class Picture &lt; ActiveRecord::Base
    has_many :reviews
  end
  </code></pre>
  
  <p>Above, I established a one-to-many relationship between pictures and reviews.</p>
  
  <p><strong>Routes</strong></p>
  
  <pre><code>favorite_picture_path    PUT   /pictures/:id/favorite(.:format)     pictures#favorite
  picture_reviews_pat      GET   /pictures/:picture_id/reviews(.:format)  reviews#index
                           POST  /pictures/:picture_id/reviews(.:format)  reviews#create
  new_picture_review_path  GET   /pictures/:picture_id/reviews/new(.:format)  reviews#new
  edit_picture_review_path GET   /pictures/:picture_id/reviews/:id/edit(.:format) reviews#edit
  pictures_review_path     GET   /pictures/:picture_id/reviews/:id(.:format)  reviews#show
                          PATCH  /pictures/:picture_id/reviews/:id(.:format)  reviews#update
                          PUT    /pictures/:picture_id/reviews/:id(.:format)  reviews#update
                          DELETE /pictures/:picture_id/reviews/:id(.:format)  reviews#destroy
  </code></pre>
  
  <p><strong>ReviewsController</strong></p>
  
  <pre><code>class ReviewsController &lt; ApplicationController
    before_action :set_review, only: [:show, :edit, :update, :destroy]
    before_filter :find_picture, only: [:index, :create, :edit, :update, :destroy]
  
  
    def edit
       @review = Review.find(params[:id])
    end
  
    def update
      @review = Review.find(params[:id])
  
      if @review.update_attributes(params[:review])
        flash[:notice] = "Review updated"
        redirect_to @picture
      else
        flash[:error] = "There was an error updating your review"
        redirect_to @picture
      end
    end
  
    private
  
      def set_review
        @review = Review.find(params[:id])
      end
  
     def find_picture
       @picture = Picture.find(params[:picture_id])
     end
  
      def review_params
        params.require(:review).permit(:username, :body, :post_id)
      end
  end
  </code></pre>
  
  <p>The problem might lie with the review_params</p>
  
  <pre><code>post_id #should be
  review_id
  </code></pre>
  
  <p><strong>Reviews#Index Page</strong></p>
  
  <pre><code>&lt;h3&gt;Reviews for &lt;%= "#{@picture.title}" %&gt;&lt;/h3&gt;
  
  &lt;table class = "reviews-table"&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Review&lt;/th&gt;
        &lt;th&gt;Username&lt;/th&gt;
        &lt;th&gt;&lt;th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
  
  &lt;tbody&gt;
    &lt;% @picture.reviews.each do |review| %&gt;
  
      &lt;tr&gt;
        &lt;td&gt;&lt;%= review.body %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= review.username %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= link_to 'Edit', edit_picture_review_path(@picture, review) %&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;% end %&gt;
  </code></pre>
  
  <p>
  </p>
  
  <pre><code>&lt;div class = 'center'&gt;
    &lt;p&gt;&lt;%= link_to 'New Review', new_reviews_path(@review), :class =&gt; "btn btn-info" %&gt;&lt;/p&gt;
    &lt;p&gt;&lt;%= link_to 'Back', picture_path, :class =&gt; "btn btn-info" %&gt;&lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Reviews#Edit Page</strong></p>
  
  <pre><code>&lt;h3&gt;Edit Review&lt;/h3&gt;
  
  &lt;div class = 'center'&gt;
  
  &lt;div class = 'center'&gt;
  
  &lt;%= form_for [:picture, @review] do |f| %&gt;
  
    &lt;p&gt;
      &lt;%= f.label :username, :class =&gt; 'marker' %&gt;&lt;br /&gt;
      &lt;%= f.text_field :username %&gt;
    &lt;/p&gt;
  
    &lt;p&gt;
      &lt;%= f.label :body, "Review", :class =&gt; 'marker' %&gt;&lt;br /&gt;
      &lt;%= f.text_area :body, :rows =&gt; "10", :cols =&gt; "10" %&gt;
    &lt;/p&gt;
  
    &lt;p&gt;
      &lt;%= f.submit "Submit Review", :class =&gt; 'btn btn-success' %&gt;
    &lt;/p&gt;
  
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>routes.rb</strong></p>
  
  <pre><code>resources :pictures do
    put :favorite, on: :member
    resources :reviews
  end
  </code></pre>
  
  <p>As you can see above, I am using nested resources.</p>
  
  <p><strong>References and External Links</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/25251561/missing-required-keys">Missing required keys</a>
  <a href="https://stackoverflow.com/questions/17687763/actioncontrollerurlgenerationerror-missing-required-keys-id">ActionController::UrlGenerationError missing required keys: [:id]</a>
  <a href="https://stackoverflow.com/questions/21708256/no-route-matches-missing-required-keys-id">No route matches missing required keys: [:id]</a>
  <a href="https://stackoverflow.com/questions/24622123/actioncontrollerurlgenerationerror-missing-required-keys-id">ActionController::UrlGenerationError: missing required keys: [:id]</a>
  <a href="https://stackoverflow.com/questions/24893712/no-routes-matches-missing-required-keys-id-id">No routes matches &quot;missing required keys: [:id, :_id]&quot;</a></p>
  
  <p>All of the above links and more consulted. Every solution tried but none worked. This is why I am re-opening this question. I hope this guide can serve as a template for this problem moving forward.</p>
  
  <p>Thanks in advance. This is not an easy question. Good luck.</p>