0

您好我正在开发一个关于用户注册的应用程序,但是当用户 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
4

1 回答 1

1

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

edit_user_registration_path ( USER_ID )

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

于 2012-07-24T18:04:30.143 回答