Last active
July 28, 2016 22:57
-
-
Save Jks15063/43d97a321d65966054d618a34de5fe0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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