ActiveRecord::RecordNotFound in UserController#show



你好,我正在开发一个关于用户注册的应用程序,但当用户X想要编辑他的信息时,该应用程序会使用"编辑"而不是用户id,并向我显示以下错误:

ActiveRecord::RecordNotFound in UserController#show
Couldn't find User with id=edit

(我是为用户设计的),这是我的家。html.rb

<body>
<div class="container">
  <% if signed_in? %>
    <table class="front" summary="For signed-in users">
      <tr>
        <td class="main">
          <h1 class="micropost">What's up?</h1>
          <%= link_to "edit your profile", edit_user_registration_path, :class => "signup_button round" %>
        </td>
      </tr>
    </table>
  <% else %>
    <h1>Sample App</h1>
    <p>
    This is the home page for the <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> sample application.
    </p>
    <%= link_to "Sign up now!", new_user_registration_path, :class => "signup_button round" %>
  <% end %>
 </div>

这是我的routes.rb(我知道应该是用户,但如果我把它作为复数,那就行不通了)

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

最后是我的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

您需要指定一个用户id,以便Rails生成正确的路由。

edit_user_registration_path ( USER_ID )

您没有向home.html.erb.

中的方法传递任何user_id

最新更新