Skip to content

Instantly share code, notes, and snippets.

@Jks15063
Last active July 28, 2016 22:57
Show Gist options
  • Save Jks15063/43d97a321d65966054d618a34de5fe0a to your computer and use it in GitHub Desktop.
Save Jks15063/43d97a321d65966054d618a34de5fe0a to your computer and use it in GitHub Desktop.
def create
begin
@todo_list = TodoList.find(params[:todo_list_id])
@todo_item = @todo_list.todo_items.new(todo_item_params)
if @todo_item.save
flash[:success] = "Added todo list item."
redirect_to todo_list_todo_items_path
else
flash[:error] = "There was a problem adding that todo list item."
render action: :new
end
rescue ActiveRecord::RecordNotFound
redirect_to new_todo_list_path
end
end
def destroy
begin
@todo_list = TodoList.find_by(id: params[:todo_list_id])
@todo_item = @todo_list.todo_items.destroy(params[:id])
puts @todo_item
puts "------------------------------------------------"
flash[:success] = "Your todo item was successfully removed."
redirect_to todo_list_todo_items_path
rescue ActiveRecord::RecordNotFound
redirect_to new_todo_list_path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment