我一直在這里使用rails,這是我第一次遇到這個問題,我在終端頂部收到此錯誤“/用戶”不是受支持的控制器名稱。這可能導致潛在的路由問題。在嘗試運行遷移以從表中洗掉某些內容時,請參閱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 我點擊了鏈接,它給了我所有我已經習慣的東西之前設定這些路線。
uj5u.com熱心網友回復:
問題在于/路徑映射中的存在。映射必須采用Controller#ActionRuby on Rails 指南中指定的格式 - https://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use。這也適用于其他路線,而不僅僅是用戶。
解決方案:通過從映射中洗掉來修改路由檔案,/如下所示
配置/路由.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
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/482390.html
