[RUBY] [No Method Error] Solution when new action occurs

Overview

I want to move to the registration screen, but I get an error and cannot display it at all: sob: As a result of falling into a situation and struggling for hours, it was resolved, so I will leave it as a memorandum.

Event

I get the following error: zap: スクリーンショット 2020-05-29 11.45.21.png

routes.rb


Rails.application.routes.draw do
  devise_for :users
  root "groups#index"

  resources :users, only: [:edit, :update]

  resources :groups, only: [:index, :new, :create, :edit, :update] do
    resources :tasks, only: [:index, :new, :create, :edit, :update, :destroy]
  end
end

html:controller.html.haml


  def new
    @task = Task.new
  end

html:main_view.html.haml


#abridgement
.new_display
  = form_for @task do |f|
#abridgement

Impressions of seeing the error

Not strange: disappointed_relieved: What are you saying: persevere: There is no data because it is a new action. I was in agony alone. .. ..

Cause

The cause is [the path automatically generated by form_for is ** plural only **]! !! It was also mentioned in the error text!

undefind method 'tasks_path' for ~

What do I say when I read that passage? ?? There is no such pass: triumph: I thought: sweat:

solution

I changed the view as below!

html:main_view.html.haml


#abridgement
.new_display
  = form_for @task, url: group_tasks_path do |f|
#abridgement

screen

スクリーンショット 2020-05-29 13.40.42.png

I hope it will be a stepping stone for those who are worried about something similar: relaxed:

reference

https://qiita.com/annaaida/items/ae38de82526bf5b4aa73

Recommended Posts

[No Method Error] Solution when new action occurs
[Rails] Solution when migration error occurs in acts-as-taggable-on
Rails <% = expression%> Why no error occurs when empty
No error message is displayed when create action fails
No static method getFont error
[Android] no such table error solution
Solution notes when an error occurs when downloading docker gpg using curl
A reminder when an aapt.exe error occurs
Solution when you get the error Webpacker :: Manifest :: MissingEntryError in Devise :: Sessions # new
Error in bundle install when running rails new
[Rails] "private method` String' called ~ "error when db: migrate
What to do when a null byte error occurs
Error ExecJS :: RuntimeUnavailable: What to do when it occurs
Solution for the error "no basic auth credentials" when pushing a Docker container to Heroku