_task.json.jbuilder has invalid arguments for project_task_url
JunichiIto opened this issue · 1 comments
JunichiIto commented
A reader of the Japanese edition found that _task.json.jbuilder
has invalid arguments for project_task_url
.
It should be:
json.url project_task_url(task.project, task, format: :json)
The current test fails if tasks_controller_spec.rb
has render_views
views option:
require 'rails_helper'
RSpec.describe TasksController, type: :controller do
+ render_views
include_context "project setup"
Failures:
1) TasksController#create responds with JSON formatted output
Failure/Error: json.url project_task_url([task.project, task], format: :json)
ActionView::Template::Error:
No route matches {:action=>"show", :controller=>"tasks", :format=>:json, :project_id=>[#<Project id: 1, name: "Project 2", description: "A test project.", due_on: "2021-03-06", created_at: "2021-02-27 07:53:57.565109000 +0000", updated_at: "2021-02-27 07:53:57.565109000 +0000", user_id: 1, completed: nil>, #<Task id: 1, name: "New test task", project_id: 1, completed: nil, created_at: "2021-02-27 07:53:57.574235000 +0000", updated_at: "2021-02-27 07:53:57.574235000 +0000">]}, missing required keys: [:id]
Did you mean? project_tasks_url
project_task_path
project_tasks_path
new_project_task_url
# ./app/views/tasks/_task.json.jbuilder:2:in `_app_views_tasks__task_json_jbuilder___3745737086157069224_66100'
# ./app/views/tasks/show.json.jbuilder:1:in `_app_views_tasks_show_json_jbuilder__4444021816594691676_66060'
# ./app/controllers/tasks_controller.rb:34:in `block (2 levels) in create'
# ./app/controllers/tasks_controller.rb:31:in `create'
# ./spec/controllers/tasks_controller_spec.rb:20:in `block (3 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# ActionController::UrlGenerationError:
# No route matches {:action=>"show", :controller=>"tasks", :format=>:json, :project_id=>[#<Project id: 1, name: "Project 2", description: "A test project.", due_on: "2021-03-06", created_at: "2021-02-27 07:53:57.565109000 +0000", updated_at: "2021-02-27 07:53:57.565109000 +0000", user_id: 1, completed: nil>, #<Task id: 1, name: "New test task", project_id: 1, completed: nil, created_at: "2021-02-27 07:53:57.574235000 +0000", updated_at: "2021-02-27 07:53:57.574235000 +0000">]}, missing required keys: [:id]
# Did you mean? project_tasks_url
# project_task_path
# project_tasks_path
# new_project_task_url
# ./app/views/tasks/_task.json.jbuilder:2:in `_app_views_tasks__task_json_jbuilder___3745737086157069224_66100'
ruralocity commented
Thank you for reporting this. I think I'm going to keep this issue open for others who may find it, but leave it unfixed for now. Due to the branching strategy I took for building out each chapter's source code changes, I have to apply the change to each branch and handle several merge conflicts as I go. This adds risk to breaking the sample code, especially in later chapters.