User Authorization -Recipes controller

Two questions on User Authorization

I have added the highlighted code for the instruction “Next, in the Recipes controller, use another before action that uses require_editor to permit only users with an editor role to access the show and edit actions”

  1. But still I get an error “Remember to add before_action require_editor to the Recipes controller”. Why is that?

class RecipesController < ApplicationController

before_action :require_editor, only: [:show, :edit]

before_action :require_user, only: [ :update, :destroy]

def show
@recipe = Recipe.find(params[:id])
end

def edit
@recipe = Recipe.find(params[:id])
end

def update
@recipe = Recipe.find(params[:id])
if @recipe.update(recipe_params)
redirect_to @recipe
else
render ‘edit’
end
end

def destroy
@recipe = Recipe.find(params[:id])
@recipe.destroy
redirect_to root_url
end

private
def recipe_params
params.require(:recipe).permit(:name, :ingredients, :instructions)
end

end

  1. When I click on “Fetch Code”, Codecademy does not fetch the correct code for this exercise and says “Something went wrong”. Can you please fix this?

It’s telling you that you did your code wrong.

First, check if you define require_editor method. Then try to put before_action require_editor below the require_user

before_action :require_user, only: [:show, :edit, :update, :destroy]

before_action :require_editor, only: [:show, :edit]