ruby-on-rails 未定义本地变量或方法`api_v1_airlines'用于#< AirlinesControllerTest:0x000000565ff5a928>

mdfafbf1  于 2023-05-08  发布在  Ruby
关注(0)|答案(1)|浏览(82)

我不知道为什么minitest不能识别我的路线:

# airlines_controller_test.rb
class AirlinesControllerTest < ActionDispatch::IntegrationTest
    test "should get index" do
      get api_v1_airlines
      assert_response :success
    end
  end

` api_v1_airlines GET    /api/v1/airlines(.:format)                                                                        api/v1/airlines#index {:params=>:slug}


我做了测试

`Error:
AirlinesControllerTest#test_should_get_index:
NameError: undefined local variable or method `api_v1_airlines' for #<AirlinesControllerTest:0x0000006532df84b8>
    test/controllers/airlines_controller_test.rb:5:in `block in <class:AirlinesControllerTest>'`

我做错了什么它不识别路线,但它在铁路路线中定义。我的测试文件中没有包含哪些内容?

uxhixvfz

uxhixvfz1#

根据文档,您应该使用路由帮助器的*_url形式。

class AirlinesControllerTest < ActionDispatch::IntegrationTest
    test "should get index" do
      get api_v1_airlines_url
      assert_response :success
    end
  end

相关问题