Skip to content
This repository was archived by the owner on Jul 21, 2024. It is now read-only.

_task.json.jbuilder has invalid arguments for project_task_url #112

Open
JunichiIto opened this issue Feb 27, 2021 · 1 comment
Open

_task.json.jbuilder has invalid arguments for project_task_url #112

JunichiIto opened this issue Feb 27, 2021 · 1 comment

Comments

@JunichiIto
Copy link
Contributor

A reader of the Japanese edition found that _task.json.jbuilder has invalid arguments for project_task_url.

json.url project_task_url([task.project, task], format: :json)

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
Copy link
Member

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants