UserController#show中的ActiveRecord :: RecordNotFound

时间:2012-07-24 17:36:45

标签: ruby-on-rails ruby activerecord controller

您好我正在开发一个关于用户注册的应用程序,但是当用户X想要编辑他的信息时,应用程序正在进行“编辑”而不是用户ID,并向我显示以下错误:

ActiveRecord::RecordNotFound in UserController#show

Couldn't find User with id=edit

(我正在为用户使用设计),这是我的home.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

1 个答案:

答案 0 :(得分:1)

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

edit_user_registration_path ( USER_ID )

您没有将任何user_id传递给home.html.erb中的方法。