Rails 4 - 帐户激活后如何重定向用户编辑用户?

时间:2014-11-18 07:42:45

标签: ruby-on-rails ruby-on-rails-4

我有以下路线。

$ rake routes
                  Prefix Verb   URI Pattern                             Controller#Action
     password_resets_new GET    /password_resets/new(.:format)          password_resets#new
    password_resets_edit GET    /password_resets/edit(.:format)         password_resets#edit
account_activations_edit GET    /account_activations/edit(.:format)     account_activations#edit
                    root GET    /                                       home_page#index
                  signup GET    /signup(.:format)                       users#new
                   login GET    /login(.:format)                        sessions#new
                         POST   /login(.:format)                        sessions#create
                  logout DELETE /logout(.:format)                       sessions#destroy
          following_user GET    /users/:id/following(.:format)          users#following
          followers_user GET    /users/:id/followers(.:format)          users#followers
                   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
                         GET    /users(.:format)                        users#index
                         POST   /users(.:format)                        users#create
                         GET    /users/new(.:format)                    users#new
                         GET    /users/:id/edit(.:format)               users#edit
                         GET    /users/:id(.:format)                    users#show
                         PATCH  /users/:id(.:format)                    users#update
                         PUT    /users/:id(.:format)                    users#update
                         DELETE /users/:id(.:format)                    users#destroy
 edit_account_activation GET    /account_activations/:id/edit(.:format) account_activations#edit
         password_resets POST   /password_resets(.:format)              password_resets#create
      new_password_reset GET    /password_resets/new(.:format)          password_resets#new
     edit_password_reset GET    /password_resets/:id/edit(.:format)     password_resets#edit
          password_reset PATCH  /password_resets/:id(.:format)          password_resets#update
                         PUT    /password_resets/:id(.:format)          password_resets#update
              microposts POST   /microposts(.:format)                   microposts#create
               micropost DELETE /microposts/:id(.:format)               microposts#destroy
           relationships POST   /relationships(.:format)                relationships#create
            relationship DELETE /relationships/:id(.:format)            relationships#destroy
$ 

当用户点击发送给用户的邮件程序中的激活帐户链接时,我希望将用户重定向到edit_user,以便他可以更新他的个人资料。现在,用户被重定向到他的索引页面,如下所示。

class AccountActivationsController < ApplicationController
  def edit
    user = User.find_by(email: params[:email])
    if user && !user.activated? && user.authenticated?(:activation, params[:id])
      user.activate
      flash[:success] = "Account activated!"
      log_in user
      redirect_to user

    else
      flash[:danger] = "Invalid activation link"
      redirect_to root_url
    end
  end
end

我应该如何更改redirect_to user来完成此操作?

1 个答案:

答案 0 :(得分:1)

你可以做......

redirect_to edit_user_path user

这将显示用户“user”的编辑用户视图。

干杯