2011-10-17 59 views
4

有沒有人知道爲什麼當我運行我的規格說它說這條路線不存在,當它明確嗎?RSpec與Rails 3.1沒有路由匹配錯誤,除了路由存在

這裏是在控制器中的相關代碼:

class JobsController < ApplicationController 
    before_filter :find_job, :only => [:show, :edit] 
    respond_to :html, :json 
    def show 
    respond_with @job 
    end 
    def find_job 
    @job = Job.find(params[:id]) 
    end 
end 

而且在routes.rb中:

resources :jobs 

而且在規格:

def valid_attributes 
    {} 
    end 

    describe "POST create" do 
    context "with valid params" do 
     it "redirects to the jobs path" do 
     post :create, :job => valid_attributes 
     response.should redirect_to job_path 
     end 
    end 
    end 

錯誤:

1) JobsController when logged in as administrator POST create with valid params redirects to the jobs path 
    Failure/Error: response.should redirect_to job_path 
    ActionController::RoutingError: 
     No route matches {:action=>"show", :controller=>"jobs"} 

當我運行rake routes我得到:

jobs GET /jobs(.:format)      {:action=>"index", :controller=>"jobs"} 
     POST /jobs(.:format)      {:action=>"create", :controller=>"jobs"} 
new_job GET /jobs/new(.:format)     {:action=>"new", :controller=>"jobs"} 
edit_job GET /jobs/:id/edit(.:format)    {:action=>"edit", :controller=>"jobs"} 
    job GET /jobs/:id(.:format)     {:action=>"show", :controller=>"jobs"} 
     PUT /jobs/:id(.:format)     {:action=>"update", :controller=>"jobs"} 
     DELETE /jobs/:id(.:format)     {:action=>"destroy", :controller=>"jobs"} 

回答

9

job_path是不是沒有一個:id參數的有效途徑。這應該工作:

job = assigns(:job) 
response.should redirect_to job_path(job) 
+0

它也適用於我,謝謝! –

相關問題