before_filter :require_owner

后端 未结 4 459
Happy的楠姐
Happy的楠姐 2021-01-02 16:28

I have a number of resources (Trips, Schedules, etc) with actions that should be limited to just the resource\'s owner.

How do you implement code with a #require_ow

4条回答
  •  执笔经年
    2021-01-02 17:11

    Or just use inherited resources:

    InheritedResources also introduces another method called begin_of_association_chain. It’s mostly used when you want to create resources based on the @current_user and you have urls like “account/projects”. In such cases you have to do @current_user.projects.find or @current_user.projects.build in your actions.

    You can deal with it just by doing:

    class ProjectsController < InheritedResources::Base
      protected
        def begin_of_association_chain
          @current_user
        end
    end
    

提交回复
热议问题