manages permissions for debate editing
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
class DebatesController < ApplicationController
|
||||
before_action :set_debate, only: [:show, :edit, :update]
|
||||
before_action :authenticate_user!, only: [:new, :create]
|
||||
|
||||
before_action :authenticate_user!, except: [:show, :index]
|
||||
before_action :validate_ownership, only: [:edit, :update]
|
||||
|
||||
def index
|
||||
if params[:tag]
|
||||
@debates = Debate.tagged_with(params[:tag])
|
||||
@@ -42,4 +43,8 @@ class DebatesController < ApplicationController
|
||||
params.require(:debate).permit(:title, :description, :tag_list, :terms_of_service)
|
||||
end
|
||||
|
||||
def validate_ownership
|
||||
raise ActiveRecord::RecordNotFound unless @debate.editable_by?(current_user)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user