title: spec for nested routes
body: <p>My routes are:</p>
  
  <pre><code>resources :posts
    resources :images
  end
  </code></pre>
  
  <p>and I want to write spec for ImagesController:</p>
  
  <pre><code>it "renders the index template" do
    get :index, {:id =&gt; @post.id}
    expect(response).to render_template("index")
  end
  </code></pre>
  
  <p>the error is </p>
  
  <pre><code>No route matches {:action=&gt;"index", :controller=&gt;"images", :id=&gt;"19"}
  </code></pre>
  
  <p>How do I fix this?</p>
  
  <p>edit:</p>
  
  <p>fixed with the <code>post_id</code> but seems it still doesn't get the parameter:</p>
  
  <p>the new error is</p>
  
  <pre><code>Failure/Error: get :index, {post_id: @post.id}
       NoMethodError: undefined method `+' for nil:NilClass
  </code></pre>
  
  <p>index view:</p>
  
  <pre><code>  def index
      @post = Post.find(params[:post_id])
      @calculations = @post.something + 1
    end
  </code></pre>