由于某些原因,我运行此功能测试
require 'test_helper'
class ListControllerTest < ActionController::TestCase
test "should get mylist" do
post :mylist, :format => :json
assert_response :success
end
end
的routes.rb
SomeApplication::Application.routes.draw do
match "/mylist" => "list#mylist", :method => "POST"
end
list_controller.rb
class ListController < ApplicationController
def mylist
respond_to do |format|
format.json { render :json => []}
end
end
end
我收到此错误:
1) Error:
test_should_get_mylist(ListControllerTest):
ActionController::RoutingError: No route matches {:controller=>"list", :format=>:json, :action=>"mylist"}
/test/functional/list_controller_test.rb:6:in `test_should_get_mylist'
有什么想法吗?
此致
米甲
答案 0 :(得分:0)
行。我知道了。那些愚蠢的错误是最难发现的。有时我会为红宝石哭泣以打字;}
问题出在routes.rb中。而不是:
match "/mylist" => "list#mylist", :method => "POST"
应该是
match "/mylist" => "list#mylist", :via => :post
感谢所有试图帮助我的人。