What to do if you get the error Couldn't find Item without an ID

What to do if id is not found

This was the controller when I got the error.

order_controller.rb


  def index
    @item = Item.find(params[:id])
    @user_item = UserItem.new
  end

Solutions

The conclusion was an error caused by not knowing that the ID name would change when nested. Searched by rails routes

item_orders GET /items/:item_id/orders(.:format) orders#index

I got the result, but what you should pay attention to is the /: item_id/part. It seems that the id name of the element that is a child element in the nest changes to [: (parent element name) _id]. In other words, the description of the correct answer is here.

order_controller.rb


  def index
    @item = Item.find(params[:item_id])
    @user_item = UserItem.new
  end

Note

It was good to know that the ID name of the model that corresponds to the nested child element changes.

Recommended Posts

What to do if you get the error Couldn't find Item without an ID
[Rails] What to do if you can't get an error message with the errors method
What to do if you get an error during rails db: reset
What to do if you get an error when you hit Heroku logs
What to do if you get an error on heroku rake db: migrate
About ActiveRecord_Relation and Couldn't find Item without an ID error
What to do if you can't get the text of an element in Selenium
What to do if you get a gcc error in Docker
What to do if you get a DISPLAY error in gym.render ()
What to do if you get an error in Basic authentication during Rails test code
What to do if you get an error saying "Could not find a JavaScript runtime." When starting rails server
[Rails] What to do if you get an error saying "Could not find a JavaScript runtime." When executing the rails s command on Catalina
What to do if you get an [An HTTP request took too long to complete.] Error in Docker.
What to do if an ActionController :: UnknownFormat error occurs
What to do if you get a SQLite3 :: BusyException: database is locked error
What to do if you get To install the missing version, run `gem install bundler: 2.1.4`
What to do if you get an error with bundle install by entering gem'bcrypt' in your Gemfile
What to do if you get the error Too long with no output (exceeded 10m0s) on CircleCI
What to do if you get a wrong number of arguments error in binding.pry
What to do if you get a java.io.IOException in GlassFish
What to do if you get a port error when docker-compose up on Mac
What to do if you can't use the rails command
[Java] What to do if you get an error in Eclipse saying "Not allowed at source level below 1.X"
What to do if you get an Argument Error: wrong number of arguments (given 2, expected 0) in your RSpec test
What to do if you get an error saying "Please enter a valid value" when getting with Rails datetime_field
What to do if you don't see the test code error message in the terminal console
What to do if you get a "Cannot Pull Container Error" when starting ECS ​​Fargate
What to do if you get a "302" error in your controller unit test code in Rails
What to do if you get angry with OpenSSL with pyenv install
What to do if you forget the root password in CentOS7
What to do if you cannot roll back the migration (UnknownMigrationVersionError)
[Rails] What to do if you can't get parameters with form_with
What to do if you install Ubuntu
What to do if you get a "Mysql2 :: Error: Operand should contain 1 column (s)" error in Rails
What to do if you get a JNI shared library error when trying to build in Eclipse
What to do if you get a groovy warning in Thymeleaf Layout
Add gem'rails-i18n','~> 6.0.0' and what to do if bundle install gives an error
What to do if you can't install the plugin from the Eclipse marketplace
What to do if an error occurs when nokogiri enters when bundle install
no space left on device What to do if an error occurs
What to do if you don't like the code generated by swagger-codegen-cli
What to do if you get a MiniMagick vulnerability alert on GitHub
What to do if the server tomcat dies
What to do if you push incorrect information
What to do if you should have installed Rails but an error occurs with rails -v (for beginners)
What to do if you get Could not locate Gemfile or .bundle / directory
What to do if you can't activate the select box created by bootstrap-select
wildflly10 java8 ERROR [org.jboss.jca.core.tx.jbossts.XAResourceRecoveryImpl] (Periodic Recovery) IJ000906 What to do if an error occurs
What to do if you get angry if you don't have nokogiri while installing wp2txt
What to do if you get an error saying Cannot find a valid baseurl for repo when you use yum -y install docker in a udemy course using CentOS7
What to do if you get a javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake in the IBM JDK
How to translate the error message into Japanese (What to do if you cannot log in for some reason)
What to do if the debug gem installation fails
What to do if the Rails server can't start
What to do if you get a NoClassDefFoundError when trying to run eclipse on Java9
What to do if you can't find your API key after deploying to Rails heroku
What to do if you cannot execute with the command "Java package name / class name"
[Solution] What to do if you get a Docker error'ERROR: Cannot connect to the Docker daemon at unix: ///var/run/docker.sock. Is the docker daemon running?'
What to do if you get the warning "Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1." in Rails 6.0
What to do if you can't find the JDK you put in SDKMAN after migrating from bash to zsh on macOS
What to do when you launch an application with rails