0

こんにちは私はユーザーの登録に関するアプリケーションを開発していますが、ユーザーXが自分の情報を編集したい場合、アプリはユーザーIDの代わりに「編集」を実行し、次のエラーを表示します。

ActiveRecord::RecordNotFound in UserController#show

Couldn't find User with id=edit

(私はユーザーのためにdeviseを使用しています)、これは私の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

Railsが正しいルートを生成するには、ユーザーIDを指定する必要があります。

edit_user_registration_path ( USER_ID )

home.html.erbのメソッドにuser_idを渡さなかった。

于 2012-07-24T18:04:30.143 に答える