Added Ingredient#destroy
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
class IngredientsController < ApplicationController
|
||||
before_action :find_project_by_project_id, only: [:index, :create]
|
||||
before_action :find_ingredient, only: [:destroy]
|
||||
before_action :authorize
|
||||
|
||||
def index
|
||||
@@ -20,6 +21,11 @@ class IngredientsController < ApplicationController
|
||||
end
|
||||
|
||||
def destroy
|
||||
# FIXME: don't destroy if any meal depend on ingredient
|
||||
if @ingredient.destroy
|
||||
flash[:notice] = 'Deleted ingredient'
|
||||
end
|
||||
redirect_to project_ingredients_url(@project)
|
||||
end
|
||||
|
||||
private
|
||||
@@ -40,4 +46,13 @@ class IngredientsController < ApplicationController
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
# :find_* methods are called before :authorize,
|
||||
# @project is required for :authorize to succeed
|
||||
def find_ingredient
|
||||
@ingredient = Ingredient.find(params[:id])
|
||||
@project = @ingredient.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user