Ruby on rails 没有路由匹配{:action=>;>;&x201C;show&&x201D;,:controller=>;>;&x201C;users&&x201D;}

Ruby on rails 没有路由匹配{:action=>;>;&x201C;show&&x201D;,:controller=>;>;&x201C;users&&x201D;},ruby-on-rails,routing,controller,Ruby On Rails,Routing,Controller,如果发生以下情况,这是我的用户控制器 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_pa

如果发生以下情况,这是我的用户控制器

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
当我在浏览器上运行它时,我得到以下信息:

Routing Error

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

我不知道为什么会发生这种情况???

您需要将
用户
对象或至少用户id传递给
链接方法,在该方法中,您正在创建您正在单击的链接。尝试类似于

还要确保控制器的名称正确,例如
userscoontroller
(复数)。

重命名两个文件:

'user\u controller.rb'
=>
'users\u controller.rb'

以及顶部的常数:

UserController
=>
userscocontroller

文件名必须与常量匹配,约定模型为单数,控制器为复数(与表匹配)

去看看吧


/users/1

如果我更改了控制器的名称,应用程序将损坏,控制器也将传递给defise_的符号多元化,该符号是
design_for:users
的方法现在出现路由错误未初始化常量用户控制器重命名控制器后需要重新启动服务器。
Routing Error

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