Asantoya17
Asantoya17

Reputation: 4725

No route matches {:action=>“show”, :controller=>“users”}

i following happens, this is my Usercontroller

class UserController < ApplicationController

def new
     @user = User.new
end

def create
    @user = User.new(params[:user])
    if @user.save
        redirect_to user_session_path
    else
    redirect_to new_user_session_path
end

end

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

in my routes.rb I have the following:

Estaciones::Application.routes.draw do
root :to => "static_pages#home"
match '/contact', :to=>'static_pages#contact'
match '/about', :to=>'static_pages#about'
devise_for :user
resources :user do
#resources :car
end

When I run it on my browser I get this:

Routing Error

No route matches {:action=>"show", :controller=>"user"}
Try running rake routes for more information on available routes.

I don't know why this happens???

Upvotes: 2

Views: 4527

Answers (2)

Kenny Grant
Kenny Grant

Reputation: 9623

Rename both the file:

'user_controller.rb' => 'users_controller.rb'

and the constant at the top:

UserController => UsersController

File names must match constants, and the convention is for models to be singular, and controllers to be plural (matching the table).

and try visiting

/users/1

Upvotes: 1

Matt
Matt

Reputation: 17629

You need to pass the User object or at least the user id to the link_to method where you're creating the link that you're clicking. Try something like <%= link_to user.name, user %>

Also make sure that your controller is properly named e.g. UsersController (plural).

Upvotes: 2

Related Questions