Skip to content

Commit 8130f8d

Browse files
Fix bugs from README.md
1 parent 0e4c8e6 commit 8130f8d

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

app/controllers/home_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def landing
99

1010
def edit_todo_item
1111
@todo_item.update(todo_item_params)
12+
render json: @todo_item
1213
end
1314

1415
def reset_todo_items
@@ -18,7 +19,7 @@ def reset_todo_items
1819
private
1920

2021
def todo_item_params
21-
params.permit(:id, :title, :checked)
22+
params.require(:home).permit(:id, :title, :checked)
2223
end
2324

2425
def set_todo_item

app/javascript/components/TodoList/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ const TodoList: React.FC<Props> = ({ todoItems }) => {
2626
todoItemId: number
2727
): void => {
2828
axios.post("/todo", {
29-
id: todoItemId,
30-
checked: e.target.checked,
31-
});
29+
home: {
30+
id: todoItemId,
31+
checked: e.target.checked,
32+
}
33+
}).then((res) => {
34+
e.target.checked = res.data.checked;
35+
});
36+
3237
};
3338

3439
const resetButtonOnClick = (): void => {

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
Rails.application.routes.draw do
44
root to: "home#landing"
55
post "todo", to: "home#edit_todo_item"
6-
post "reset", to: "home#reset_todo_item"
6+
post "reset", to: "home#reset_todo_items"
77
end

0 commit comments

Comments
 (0)