Ruby on rails more elegant way to authenticate that users can edit only their own content

后端 未结 3 823
傲寒
傲寒 2021-01-07 04:07

I currently authenticate that users can edit their own content only by:

@posts = current_user.posts.find(params[:id])

Is t

3条回答
  •  走了就别回头了
    2021-01-07 04:41

    CanCan is another gem that offers authorization functionality. It's all managed in one ruby file and can then be incorporated into controllers with one line. There's also a number of view helpers so you can use <% if can? :update, @article %> in your views.

提交回复
热议问题