ruby-on-rails – 带有Rails的RSpec 3.1除路由存在外,没有路由匹
发布时间:2020-12-17 03:45:38 所属栏目:百科 来源:网络整理
导读:有没有人知道为什么当我运行我的规格它说这条路线不存在时,它显然是什么时候? 这是控制器中的相关代码: class JobsController ApplicationController before_filter :find_job,:only = [:show,:edit] respond_to :html,:json def show respond_with @job e
有没有人知道为什么当我运行我的规格它说这条路线不存在时,它显然是什么时候?
这是控制器中的相关代码: 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路线时,我得到: 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) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |