0

ログインまたはサインアップした後、ユーザーは個々のショーページにリダイレクトされます。Hartl のガイドからいくつかのコードを使用していますが、動作させることができないようです:

コントローラ:

class UsersController < ApplicationController
    before_filter :authenticate_user!

  def show
    @user = User.find(params[:id])
  end

  def new
  end

  def create
    @user = User.new(user_params)
    if @user.save
        flash[:success] = "Welcome to the Sample App!"
      redirect_to @user
    else
      redirect_to login_path
    end
  end

private

    def user_params
      params.require(:user).permit(:name, :email, :password,
                                   :password_confirmation)
    end

end

ルート:

  devise_for :users, :path => '', :path_names => { :sign_in => 'login', :sign_out => 'logout',
                                      :password => 'password', :confirmation => 'verification',
                                      :unlock => 'unblock', :registration => 'signup',
                                      :sign_up => 'new' }

  devise_scope :user do
    get   'login',        to: 'devise/sessions#new'
    get   "logout",       :to => "devise/sessions#destroy"
    get   "signup",       :to => "devise/registrations#new"
    get   "password", :to => "devise/passwords#new"
    match 'users/secret',   to: "devise/passwords#create",      via: :post
    match 'sessions/user',  to: 'devise/sessions#create',       via: :post
    match 'users/signup',   to: 'devise/registrations#create',  via: :post
  end

  resources :users
  resources :sessions    

  root 'home#index'

リダイレクトが機能するようになるまで、私/views/users/show.html.erbのページは単純なページです。

編集:

レーキルート

                  Prefix Verb   URI Pattern                  Controller#Action
        new_user_session GET    /login(.:format)             devise/sessions#new
            user_session POST   /login(.:format)             devise/sessions#create
    destroy_user_session DELETE /logout(.:format)            devise/sessions#destroy
           user_password POST   /password(.:format)          devise/passwords#create
       new_user_password GET    /password/new(.:format)      devise/passwords#new
      edit_user_password GET    /password/edit(.:format)     devise/passwords#edit
                         PATCH  /password(.:format)          devise/passwords#update
                         PUT    /password(.:format)          devise/passwords#update
cancel_user_registration GET    /signup/cancel(.:format)     devise/registrations#cancel
       user_registration POST   /signup(.:format)            devise/registrations#create
   new_user_registration GET    /signup/new(.:format)        devise/registrations#new
  edit_user_registration GET    /signup/edit(.:format)       devise/registrations#edit
                         PATCH  /signup(.:format)            devise/registrations#update
                         PUT    /signup(.:format)            devise/registrations#update
                         DELETE /signup(.:format)            devise/registrations#destroy
                   login GET    /login(.:format)             devise/sessions#new
                  logout GET    /logout(.:format)            devise/sessions#destroy
                  signup GET    /signup(.:format)            devise/registrations#new
                password GET    /password(.:format)          devise/passwords#new
            users_secret POST   /users/secret(.:format)      devise/passwords#create
           sessions_user POST   /sessions/user(.:format)     devise/sessions#create
            users_signup POST   /users/signup(.:format)      devise/registrations#create
                   users GET    /users(.:format)             users#index
                         POST   /users(.:format)             users#create
                new_user GET    /users/new(.:format)         users#new
               edit_user GET    /users/:id/edit(.:format)    users#edit
                    user GET    /users/:id(.:format)         users#show
                         PATCH  /users/:id(.:format)         users#update
                         PUT    /users/:id(.:format)         users#update
                         DELETE /users/:id(.:format)         users#destroy
                sessions GET    /sessions(.:format)          sessions#index
                         POST   /sessions(.:format)          sessions#create
             new_session GET    /sessions/new(.:format)      sessions#new
            edit_session GET    /sessions/:id/edit(.:format) sessions#edit
                 session GET    /sessions/:id(.:format)      sessions#show
                         PATCH  /sessions/:id(.:format)      sessions#update
                         PUT    /sessions/:id(.:format)      sessions#update
                         DELETE /sessions/:id(.:format)      sessions#destroy
                    root GET    /                            home#index
4

1 に答える 1

0

問題は、rake routes 出力の最後の行にあります。

  root GET    /                            home#index

あなたのこの行を指しているroutes.rb

 root 'home#index'

その行を削除してroutes.rb、ルートパスにしたいものに置き換える必要があります。

于 2013-11-03T20:48:23.013 に答える