ActionController::RoutingError:没有路由匹配 [POST]
require 'test_helper'
class MyTest < ActionController::IntegrationTest
test "view posts from login page" do
visit("/logins/new")
find_field('Username').set('abode')
find_field('Password').set('efghi')
click_link_or_button('Login')
assert page.has_content?('Signed in!')
end
test "go to new user page" do
visit("/logins/new")
click_link("New user?")
assert (current_path == "/users/new")
end
end
Error:
test_view_posts_from_login_page(MyTest):
ActionController::RoutingError: No route matches [POST] "/logins/new"
test/integration/view_posts_test.rb:12:in `block in <class:MyTest>'
它显示第 12 行错误。“登录”按钮或 /logins/new 路径是否有问题?第二个测试通过了,所以路径应该是正确的?我做错了什么?
谢谢!
require 'test_helper'
class MyTest < ActionController::IntegrationTest
test "view posts from login page" do
visit("/logins/new")
find_field('Username').set('abode')
find_field('Password').set('efghi')
click_link_or_button('Login')
assert page.has_content?('Signed in!')
end
test "go to new user page" do
visit("/logins/new")
click_link("New user?")
assert (current_path == "/users/new")
end
end
Error:
test_view_posts_from_login_page(MyTest):
ActionController::RoutingError: No route matches [POST] "/logins/new"
test/integration/view_posts_test.rb:12:in `block in <class:MyTest>'
It shows error for line 12. Is there a problem with button "Login" or the /logins/new path? The second test passes though so the path should be correct? What am I doing wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
真的很难说清楚这里发生了什么。一般来说,如果您询问有关路由错误的问题,您也应该发布您的routes.rb 文件中的内容。
话虽这么说,我认为无论为表单生成什么 HTML,它的操作都指定不正确。
示例路线:
请注意第二列中显示“POST”的位置。这意味着新对象表单的操作属性应设置为 /tags。那里告诉 Rails 在标签控制器中呈现创建操作。您的登录模型也是如此。
至于您的表单 HTML 代码实际上是什么样子,它可能看起来类似于:
何时应该
希望这会有所帮助。
It's really hard to tell what's going on here. In general if you are asking a question about a routing error you should post what's in your routes.rb file as well.
That being said, I think whatever HTML gets generated for the form has it's action specified incorrectly.
Example routes:
Notice where it says POST in the second column there. That means the action attribute for a new object form should be set to /tags. Having that there tells Rails to render the create action in the Tags controller. The same would be true for your login model.
As far as what your form HTML code actually looks like, it probably looks something along the lines of:
When it should be
Hope this helps.
我认为您的视图文件中的表单具有空白的
action
属性,因此它将表单发布到/logins/new
而不是例如。/logins
可能映射到您的create
操作。I would think that the form in your view file is having a blank
action
-attribute, therefore it POSTs the form to/logins/new
instead of eg./logins
which probably maps to yourcreate
-action.