Rails Model Versioning with Approval

最后都变了- 提交于 2019-12-29 14:37:11

问题


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?


回答1:


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



回答2:


There is a Draftsman gem. It lets you create draft versions of your database records. Read more here. You will have to add an admin interface.



来源:https://stackoverflow.com/questions/6229515/rails-model-versioning-with-approval

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!