Home>

I'm making a task management app with Ruby on Rails ☺️
I want to create a board as a parent and implement it so that I can get and display multiple tasks as children.

Flying from the link on commons/board,

= link_to'Display task list', board_tasks_path (board), controller: "tasks", action: "index"


task # index

def index
    board = Board.find (params [: board_id])
    @tasks = board.tasks.all
    @task = board.tasks.find (params [: board_id])
  end


Go in the direction of displaying.

ActiveRecord :: RecordNotFound in TasksController # index
Couldn't find Task with'id'= 1 [WHERE "tasks". "Board_id" = $1]


Since title and content are not included in task_id in params, I thought it was an error that could not be displayed at the transition destination.

It is the pry result of task_params and params ↓
https://gist.github.com/nikikoh/be429d07b72df01f9e59c99cc8876847

rake routes ↓
https://gist.github.com/nikikoh/198b682f769990a2730b93757e7e8023

Corresponding source code

Ruby on Rails
https://github.com/nikikoh/todo-niki

What I tried

First of all, regarding the current situation, I think about routing with board_id and task_id too much.

"board" =>"task" =>{"title" =>"aaaaaaaa", "content" =>"aaaaaaaaaaaa"}


I wondered if both routing and params had become tattered as a result.

  • Answer # 1

    No, it's a controller mistake.
    It probably doesn't exist because @task on the 7th line looks for Task by boad id instead of task id.
    Why do I need more @tasks when I get them all with @tasks?
    Maybe because of new registration on the Task list screen?
    Then it's new () instead of find.

Related articles