【发布时间】:2013-12-15 01:07:23
【问题描述】:
我正在尝试让用户停用他们的帐户,然后重新激活他们的帐户。我有代码允许在停用帐户时将 is_active 整数值更改为 0。
我正在使用 devise 3、rails 4 和 postgres。
这是我在 app/controllers/registration_controller.rb 中的销毁方法,它覆盖了设计的方法并将数据保存在数据库中。
def destroy
@user = User.find(current_user.id)
@user.is_active = 0
if @user.save
set_flash_message :notice, :destroyed
sign_out @user
redirect_to root_path
else
render "edit"
end
end
然后我复制了这个想法并制作了一个用于激活帐户的按钮,并在同一个注册控制器中使用了此代码:
def activate
@user = User.find(current_user.id)
@user.is_active == nil
if @user.save
set flash_message :notice
redirect_to edit_user_registration_path
else
render "edit"
end
end
如何将 is_active 整数类型设置回空格?
【问题讨论】:
-
考虑将is_active设为布尔数据类型,默认为true,根据需要设置为false
标签: ruby-on-rails postgresql devise ruby-on-rails-4