class TodoLists::ListsController
Constants
- List
Attributes
last_input[RW]
Public Instance Methods
delete()
click to toggle source
# File lib/todo_lists/controllers/lists_controller.rb, line 26 def delete list_index = last_input.split(' ')[1] list = List.find_by_index(list_index) if list print 'Are you sure? Enter \'y/n\': ' get_input if last_input.downcase == 'y' list.items.destroy_all list.destroy end end end
edit()
click to toggle source
# File lib/todo_lists/controllers/lists_controller.rb, line 15 def edit list_index = last_input.split(' ')[1] list = List.find_by_index(list_index) if list print 'Enter new title: ' get_input list.title = last_input list.save end end
get_input()
click to toggle source
# File lib/todo_lists/controllers/lists_controller.rb, line 66 def get_input @last_input = gets.strip end
help()
click to toggle source
# File lib/todo_lists/controllers/lists_controller.rb, line 7 def help puts "\nOptions available" puts '/new (for a new list)' puts '/edit {list_number}' puts '/delete {list_number}' puts end
index()
click to toggle source
# File lib/todo_lists/controllers/lists_controller.rb, line 41 def index if List.count == 0 puts 'You have no TodoList, create one or type \'/exit\'' else puts "\n---------------TodoLists---------------" puts '# title' puts '-- -----' List.all.each.with_index(1) do |list, index| puts "#{index}: #{list.title.capitalize}" end end end
new()
click to toggle source
# File lib/todo_lists/controllers/lists_controller.rb, line 54 def new print 'Enter Title: ' get_input return if last_input == '/exit' list = List.new(title: last_input) list.save end