Just added an Admin model to Devise. I am on Rails 4.
只是添加了一个管理模型来设计。我在Rails 4上。
I would like to give the Admin privileges to destroy and update articles that other users have created.
我想授予管理员权限来销毁和更新其他用户创建的文章。
Having trouble finding documentation on how to do so.
很难找到如何做到这一点的文档。
Right now I have this on my index page, which allows the current creator to destroy/edit:
现在我的索引页上有这个,它允许当前的创建者销毁/编辑:
<% if current_user == article.user %>
<p>
<%= link_to 'Edit', edit_article_path(article) %>
<%= link_to 'Destroy', article, method: :delete, data: { confirm: 'Are you sure?' } %>
</p>
<%end%>
Would I add something here to let admins be able to do this as well?
我是否可以在这里添加一些东西,让管理员也能这样做?
Also here is my destroy action in articles_controller:
这是我在articles_controller中的销毁操作:
def destroy
@article = current_user.articles.find(params[:id])
@article.destroy
respond_to do |format|
format.html { redirect_to articles_url, notice: 'Article was successfully destroyed.' }
format.json { head :no_content }
end
end
Thank you for all of your help! Still a rails newbie. Tons to learn. If this is already documented somewhere could you please point me in that direction. Thanks!
谢谢你的帮助!我还是一个rails新手。吨学习。如果这已经被记录在某个地方,你可以告诉我那个方向。谢谢!
1 个解决方案
#1
0
Here you go. Quite an extensive documentation:
给你。一个相当广泛的文档:
https://github.com/plataformatec/devise/blob/master/README.md
https://github.com/plataformatec/devise/blob/master/README.md
Very first steps are to simply add
第一步是简单地添加。
before_action :authenticate_user!
to your controllers.
你的控制器。
If you also need authorization have a look at cancan:
如果你还需要授权,可以看看cancan:
https://github.com/ryanb/cancan
https://github.com/ryanb/cancan
Or rather https://github.com/elabs/pundit since CanCan is no longer maintained.
或者更确切地说,是https://github.com/elabs/pundit,因为CanCan不再被维护。
#1
0
Here you go. Quite an extensive documentation:
给你。一个相当广泛的文档:
https://github.com/plataformatec/devise/blob/master/README.md
https://github.com/plataformatec/devise/blob/master/README.md
Very first steps are to simply add
第一步是简单地添加。
before_action :authenticate_user!
to your controllers.
你的控制器。
If you also need authorization have a look at cancan:
如果你还需要授权,可以看看cancan:
https://github.com/ryanb/cancan
https://github.com/ryanb/cancan
Or rather https://github.com/elabs/pundit since CanCan is no longer maintained.
或者更确切地说,是https://github.com/elabs/pundit,因为CanCan不再被维护。