Skip to content

Instantly share code, notes, and snippets.

@Choongkyu
Created September 16, 2014 15:35
Show Gist options
  • Save Choongkyu/8fdf15f1d9b9d89b3a4f to your computer and use it in GitHub Desktop.
Save Choongkyu/8fdf15f1d9b9d89b3a4f to your computer and use it in GitHub Desktop.
todos_controller
class TodosController < ApplicationController
def index
@todoAll = Todo.all
@todo = Todo.where(completed:false)
@completes = Todo.where(completed:true)
end
def todoParams
params.require(:todo).permit(:name, :completed)
end
def destroy
@todo = Todo.find(params[:id])
@todo.destroy
redirect_to :action => 'index'
end
def create
@todo=Todo.new(params)
@todo.userID = current_user
@todo.completed = false
@todo.save
redirect_to :action => 'index'
end
def complete
@todo = Todo.find(params[:id])
if @todo.completed == false
@todo.update_attribute(:completed, true)
else
@todo.update_attribute(:completed, false)
end
redirect_to :action => 'index'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment