【发布时间】:2021-01-11 05:24:24
【问题描述】:
我是 Rails 新手,我有一个页面,用户可以使用 button_to 取消他们的帐户。但是,如何将用户重定向到另一个页面?例如,我想在删除他们的帐户时重定向到取消后页面说“再见”。
我尝试查看是否有 after_user_deletion 设计方法可以覆盖但没有。
这是我在 Devise 注册下的编辑视图中看到的内容。
<div id="modal">
<p>Are you sure you want to cancel?</p>
<%= button_to "Yes", registration_path(resource_name), method: :delete%>
<button>No</button>
</div>
我不确定是否需要制作另一个控制器,但我制作了一个取消控制器。
class CancellationController < ApplicationController
before_action :authenticate_user!
def cancel
end
end
这是我在 routes.rb 中的内容
Rails.application.routes.draw do
devise_for :users
root to: 'dashboard#index'
devise_scope :user do
get 'cancel' => 'cancellation#cancel'
end
end
这是 rake 路由的内容:
【问题讨论】:
-
在你的取消方法中,删除用户,然后写
redirect_to post_cancellation_path,然后在路由中创建一个取消后路径并创建它的视图和控制器
标签: ruby-on-rails ruby model-view-controller devise