Joe Smith
Joe Smith

Reputation: 244

Unfamiliar error: ActionController::RoutingError at /show uninitialized constant UserController?

I am getting this error:

ActionController::RoutingError at /show

uninitialized constant UserController

I have checked my routes, and controller several times and they seem fine so I will post them below

class UsersController < ApplicationController
  def index
    @users = User.all
  end

  def show
    @user = User.find(params[:id])
  end

  def user_params
    params.require(:user).permit(:image, :name)
  end
 end

the route:

get 'index' => 'users#index'
get 'show' => 'user#show'

the attempted link to the show page from the index view:

<h4 class="media-heading"><%= link_to user.name, show_path %></h4>

Thanks for the help, will gladly post more info if needed.

Upvotes: 0

Views: 145

Answers (1)

Andrey Deineko
Andrey Deineko

Reputation: 52357

  1. You have an error in routes:

get 'show' => 'user#show' should be get 'show', to: 'users#show'

  1. You don't have show action in your controller

  2. I would use RESTful routes, which is simply:

resources :users # this will generate routes for you

You can specify which actions you want, or which you want to restrict using only or except options as @D-Side says in comments

Upvotes: 3

Related Questions