Rails No route matches, on Polymorphic new action test
<p>This is my first time with polymorphic associations, so the error is probably something trivial.</p>

<p>From the start, models: </p>

<pre><code>class Comment &lt; ActiveRecord::Base
  belongs_to :comment_owner, polymorphic: true 
end

class Announcement &lt; ActiveRecord::Base
  has_many :comments, as: :comment_owner
end
</code></pre>

<p>Routes: </p>

<pre><code>  resources :announcements do
    resources :comments
  end
</code></pre>

<p>Comment controller new action:</p>

<pre><code>class CommentsController &lt; ApplicationController
  before_filter :find_comment_owner

  def new
    @comment = @comment_owner.comments.new
  end

  private

  def find_comment_owner
    # Switch comment_owner_string into constant
    @klass = params[:comment_owner_type].capitalize.constantize
    @comment_owner = @klass.find(params[:comment_owner_id])
  end
end
</code></pre>

<p>And finally test:</p>

<pre><code>  describe 'New action test' do
    let(:dummy_post) do
      create(:announcement)
    end
    before :each do
      get :new, comment_owner_id: dummy_post.id, comment_owner_type: dummy_post.class.name
    end

    it 'return redirect http status' do
      expect(response).to have_http_status(:success)
    end
  end
</code></pre>

<p>And my error:</p>

<pre><code> ActionController::UrlGenerationError:
   No route matches {:action=&gt;"new", :comment_owner_id=&gt;"27", :comment_owner_type=&gt;"Announcement", :controller=&gt;"comments"}
</code></pre>

<p>My thoughts,Routes should be <a href="http://thelazylog.com/posts/polymorphic-routes-in-rails" rel="nofollow">fine</a>, the Action is build upon this <a href="http://pathfindersoftware.com/2008/07/drying-up-rails-controllers-polymorphic-and-super-controllers/" rel="nofollow">tutorial</a>, params for comment_owner should have no meaning at this time, since it can`t find the new action in the comments controller. </p>