Home > Blockchain >  Since when is users not a supported controller name?
Since when is users not a supported controller name?

Time:05-25

I have been working with rails here for a little bit and this is the first time I have run into this issue I am getting this error in the top of the terminal '/users' is not a supported controller name. This can lead to potential routing problems. See https://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use followed with a bunch of other stuff while trying to run a migration to remove something from a table.

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

my routes and my schema set up pretty much like I always have and I get the error above in the terminal I am just trying to remove the user_id from roles I followed the link and it gave me all of the stuff that I already have used to set these kind of routes before.

CodePudding user response:

The issue lies with the / present in the mapping for the paths. The mapping must be of the form Controller#Action as specified in the Ruby on Rails guides - https://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use. This is applicable for the other routes as well and not just users.

Solution: Modify the routes file by removing the / from the mapping as shown below

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
  • Related