我已经用开发环境测试了我的项目,并且一切正常,但是将项目上传到主机后,出现了此错误。
# log
[2020-02-17T14:54:55.319109 #2097106] INFO -- : [2ac848c8-15f3-47fd-ad77-ede940b1502e] Started POST "/admin/users" for my_server_ip at 2020-02-17 14:54:55 -0500
[2020-02-17T14:54:55.320555 #2097106] FATAL -- : [2ac848c8-15f3-47fd-ad77-ede940b1502e]
[2ac848c8-15f3-47fd-ad77-ede940b1502e] ActionController::RoutingError (No route matches [POST] "/users"):
[2ac848c8-15f3-47fd-ad77-ede940b1502e]
[2ac848c8-15f3-47fd-ad77-ede940b1502e] actionpack (6.0.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:36:in `call'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] actionpack (6.0.2.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] railties (6.0.2.1) lib/rails/rack/logger.rb:38:in `call_app'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] railties (6.0.2.1) lib/rails/rack/logger.rb:26:in `block in call'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `block in tagged'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:28:in `tagged'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in `tagged'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] railties (6.0.2.1) lib/rails/rack/logger.rb:26:in `call'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] actionpack (6.0.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] actionpack (6.0.2.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] rack (2.1.2) lib/rack/method_override.rb:24:in `call'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] rack (2.1.2) lib/rack/runtime.rb:24:in `call'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] activesupport (6.0.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] actionpack (6.0.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] actionpack (6.0.2.1) lib/action_dispatch/middleware/static.rb:126:in `call'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] rack (2.1.2) lib/rack/sendfile.rb:113:in `call'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] actionpack (6.0.2.1) lib/action_dispatch/middleware/host_authorization.rb:83:in `call'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] railties (6.0.2.1) lib/rails/engine.rb:526:in `call'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] /opt/passenger-5.3.7-2.el7.cloudlinux/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] /opt/passenger-5.3.7-2.el7.cloudlinux/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:157:in `accept_and_process_next_request'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] /opt/passenger-5.3.7-2.el7.cloudlinux/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:110:in `main_loop'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] /opt/passenger-5.3.7-2.el7.cloudlinux/src/ruby_supportlib/phusion_passenger/request_handler.rb:415:in `block (3 levels) in start_threads'
[2ac848c8-15f3-47fd-ad77-ede940b1502e] /opt/passenger-5.3.7-2.el7.cloudlinux/src/ruby_supportlib/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'
这是我的路线
# config/routes.rb
namespace :admin do
resources :users
end
这是我的表格
# app/views/admin/users/index.html.erb
<%= form_with(model: admin_user, local: true) do |form| %>
# my form inputs
<%= form.submit class: 'btn btn-dark' %>
<% end %>
答案 0 :(得分:0)
$ rails routes
的输出:
Prefix Verb URI Pattern Controller#Action
admin_users GET /admin/users(.:format) admin/users#index
POST /admin/users(.:format) admin/users#create
new_admin_user GET /admin/users/new(.:format) admin/users#new
edit_admin_user GET /admin/users/:id/edit(.:format) admin/users#edit
admin_user GET /admin/users/:id(.:format) admin/users#show
PATCH /admin/users/:id(.:format) admin/users#update
PUT /admin/users/:id(.:format) admin/users#update
DELETE /admin/users/:id(.:format) admin/users#destroy
如果您尝试从表单路由至此,则需要使用:
<%= form_with(model: [:admin, @user]) do |f| %>
请参阅:
答案 1 :(得分:0)
您创建的路由在名称空间admin
下,但是您正在向/users
发出pos请求。
使用/admin/users
尝试相同的请求。