gpt4 book ai didi

ruby-on-rails - RSpec with Rails 3.1 没有路由匹配错误,除了路由存在

转载 作者:行者123 更新时间:2023-12-04 05:34:28 25 4
gpt4 key购买 nike

有没有人知道为什么当我运行我的规范时,它说这条路线不存在,而它显然存在?

这是 Controller 中的相关代码:

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"}

最佳答案

job_path没有 :id 不是有效的路由范围。这应该有效:

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

关于ruby-on-rails - RSpec with Rails 3.1 没有路由匹配错误,除了路由存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7800961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com