经批准的 Rails 模型版本控制 [英] Rails Model Versioning with Approval

查看:26
本文介绍了经批准的 Rails 模型版本控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个成员可以更新的模型,但他们的更改在管理员批准他们的更改之前不会生效.有没有人解决过同样的问题,你会推荐哪些 gems 进行版本控制?纸迹?维斯塔版本?

I have a model that members will be able to update but their changes wont take effect until an admin approves their changes. Has anyone solved this same problem and what gems would you recommend for versioning? PaperTrail? Vestal versions?

推荐答案

也许你可以稍微改变一下vestal_versions.如果进行更改的用户不是管理员,则在您的控制器中添加一个 after_update 操作,该操作将回滚到以前的版本.然后,您可以将实例的状态设置为待处理,这会提醒管理员进行审查.然后,管理员只需审核最新版本,并在获得批准后将其升级.

Perhaps you could use vestal_versions with a slight twist. Add an after_update action in your controller which rolls back to the previous version if the user who made the change is not an admin. Then you can set the instance's status to pending, which would alert an admin for review. The admin would then just review the latest version and move it up if approved.

# model_controller.rb
after_update :rollback_if_not_admin

def rollback_if_not_admin
  unless current_user.admin?
  #roll back changes
  version = @model_instance.versions.count
  if version > 1
    @model_instance.reset_to!(version - 1)
    @model_instance.status = "pending"
  end

  flash[:notice] = "Your changes will be reflected once an admin has reviewed them"
  redirect_to @model_instance
end

这篇关于经批准的 Rails 模型版本控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆