登录或注册后,用户应该被重定向到他们的个人展示页面。我正在使用 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