从什么时候开始 users 不是受支持的控制器名称?
Since when is users not a supported controller name?
我在这里使用 rails 已经有一段时间了,这是我第一次 运行 遇到这个问题我在终端 '/users 的顶部收到这个错误' 不是受支持的控制器名称。这可能会导致潜在的路由问题。在尝试 运行 迁移以从 table.
中删除某些内容时,请参阅 https://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use 以及其他一些内容
Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
### USERS ROUTES ###
get "/users" => "/users#index"
post "/users" => "/users#create"
get "/users/:id" => "/users#show"
patch "/users/:id" => "/users#update"
delete "/users/:id" => "/users#destroy"
### ROLES ROUTES ###
get "/roles" => "/roles#index"
post "/roles" => "/roles#create"
### GROUPS ROUTES ###
get "/groups" => "/groups#index"
get "/groups/:id" => "/groups#show"
patch "/groups/:id" => "/groups#update"
end
ActiveRecord::Schema.define(version: 2022_05_24_161744) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "groups", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "roles", force: :cascade do |t|
t.string "title"
t.integer "user_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "users", force: :cascade do |t|
t.string "first_name"
t.string "last_name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
end
我的路线和我的架构设置与我一直以来的设置非常相似,我在终端中收到上面的错误我只是想从角色中删除 user_id 我遵循 link 和它给了我以前用来设置这些路线的所有东西。
问题出在路径映射中的 /
。映射必须采用 Controller#Action
格式,如 Rails 指南中的 Ruby - https://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use 中所指定。
这也适用于其他路线,而不仅仅是用户。
解决方案:通过从映射中删除 /
来修改路由文件,如下所示
config/routes.rb
Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
### USERS ROUTES ###
get "/users" => "users#index"
post "/users" => "users#create"
get "/users/:id" => "users#show"
patch "/users/:id" => "users#update"
delete "/users/:id" => "users#destroy"
### ROLES ROUTES ###
get "/roles" => "roles#index"
post "/roles" => "roles#create"
### GROUPS ROUTES ###
get "/groups" => "groups#index"
get "/groups/:id" => "groups#show"
patch "/groups/:id" => "groups#update"
end
我在这里使用 rails 已经有一段时间了,这是我第一次 运行 遇到这个问题我在终端 '/users 的顶部收到这个错误' 不是受支持的控制器名称。这可能会导致潜在的路由问题。在尝试 运行 迁移以从 table.
中删除某些内容时,请参阅 https://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use 以及其他一些内容Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
### USERS ROUTES ###
get "/users" => "/users#index"
post "/users" => "/users#create"
get "/users/:id" => "/users#show"
patch "/users/:id" => "/users#update"
delete "/users/:id" => "/users#destroy"
### ROLES ROUTES ###
get "/roles" => "/roles#index"
post "/roles" => "/roles#create"
### GROUPS ROUTES ###
get "/groups" => "/groups#index"
get "/groups/:id" => "/groups#show"
patch "/groups/:id" => "/groups#update"
end
ActiveRecord::Schema.define(version: 2022_05_24_161744) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "groups", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "roles", force: :cascade do |t|
t.string "title"
t.integer "user_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "users", force: :cascade do |t|
t.string "first_name"
t.string "last_name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
end
我的路线和我的架构设置与我一直以来的设置非常相似,我在终端中收到上面的错误我只是想从角色中删除 user_id 我遵循 link 和它给了我以前用来设置这些路线的所有东西。
问题出在路径映射中的 /
。映射必须采用 Controller#Action
格式,如 Rails 指南中的 Ruby - https://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use 中所指定。
这也适用于其他路线,而不仅仅是用户。
解决方案:通过从映射中删除 /
来修改路由文件,如下所示
config/routes.rb
Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
### USERS ROUTES ###
get "/users" => "users#index"
post "/users" => "users#create"
get "/users/:id" => "users#show"
patch "/users/:id" => "users#update"
delete "/users/:id" => "users#destroy"
### ROLES ROUTES ###
get "/roles" => "roles#index"
post "/roles" => "roles#create"
### GROUPS ROUTES ###
get "/groups" => "groups#index"
get "/groups/:id" => "groups#show"
patch "/groups/:id" => "groups#update"
end