Created
September 16, 2014 15:35
-
-
Save Choongkyu/8fdf15f1d9b9d89b3a4f to your computer and use it in GitHub Desktop.
todos_controller
This file contains 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
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