Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
35 lines (27 sloc) 666 Bytes
class ItemsController < ApplicationController
before_action :_set_item, only: [:update, :destroy]
before_action :_set_list
def create
@item = Item.create(_item_params.merge(completed: false))
end
def update
if params.keys.include? "completed"
@item.update(completed: params[:completed])
else
@item.update(_item_params)
end
end
def destroy
@item.destroy
end
private
def _item_params
params.require(:item).permit(:name, :price, :quantity, :list_id)
end
def _set_item
@item = Item.find(params[:id])
end
def _set_list
@list = List.find(params[:list_id] || params[:item][:list_id])
end
end
You can’t perform that action at this time.