[Ruby on Rails] undefined method ʻid'for nil: NilClass error resolution method

"undefined method ʻid'for nil: NilClass" error

スクリーンショット 2020-05-20 19.33.13.png

If you get an error such as NoMethodError undefined method ʻid'for nil: NilClass error even though you haven't made a mistake, what could be the cause? I got an error saying that the method wasn't defined ... why did I get an error like this when I defined it properly ...

This implementation is used when the logged-in user can see his information but does not want to show it to other users.

<% if @user.id == current_user.id %>



 You realize that you are wondering why this happened even though the code you implemented was correct!

#### I wasn't logged in!

 It is natural because it is a process that does not work unless you are logged in ^ _ ^;
 After logging in and checking again, the error was successfully resolved!

 ![S__56467458.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/587506/5de0eeb3-502a-6ac6-6c0a-66c553e19f79.jpeg)


Recommended Posts

[Ruby on Rails] undefined method ʻid'for nil: NilClass error resolution method
[Ruby on Rails] Follow function undefined method ʻid'for nil: NilClass error resolution
[Ruby on Rails] NoMethodError undefined method `devise_for'error resolution
Rails error undefined method ʻimage_name'for nil: NilClass handling
rspec Error: ActionView :: Template :: Error: undefined method `name'for nil: NilClass
[Ruby on Rails] Convenient helper method
Ruby on Rails installation method [Mac edition]
RSpec error resolution undefined method `feature'for RSpec: Module
[Ruby on Rails] NoMethodError: undefined method `t'for # <ActiveRecord :: Migration: 〇〇〇〇> Dealing with errors
[Ruby on Rails] How to display error messages
Ruby on Rails address automatic input implementation method
[Ruby on Rails] How to use session method
[Ruby on Rails] Individual display of error messages
Ruby on Rails Elementary
Ruby on Rails basics
rails error resolution summary
Ruby On Rails Association
Error resolution on Heroku
Method summary to update multiple columns [Ruby on Rails]
[Ruby] Invalid multibyte char (UTF-8) Error resolution method [CSV]
Ruby on Rails Refactoring method example summary around MVC
[Ruby on Rails] Search function (model, method selection formula)
About the relationship between Rails credentials.yml.enc and master.key (undefined method `[]'for nil: NilClass (NoMethodError))
Ruby on rails learning record -2020.10.03
Portfolio creation Ruby on Rails
Ruby on rails learning record -2020.10.04
[Ruby on Rails] Debug (binding.pry)
Ruby on rails learning record -2020.10.05
Ruby on rails learning record -2020.10.09
Ruby on Rails config configuration
Ruby on Rails basic learning ①
[Ruby on Rails] about has_secure_password
Ruby on rails learning record-2020.10.07 ②
From Ruby on Rails error message display to Japanese localization
Ruby on Rails record search, create if not find_or_create_by method
Commentary on partial! --Ruby on Rails
Ruby on rails learning record-2020.10.07 ①
Cancel Ruby on Rails migration
[Ruby] Notes on gets method
Ruby on rails learning record -2020.10.06
Ruby on Rails validation summary
Ruby on Rails Basic Memorandum
When using Slim in Ruby on Rails, "undefined local variable or method` f'for "is displayed in form_with
[Ruby on Rails] Use the resources method to automatically create routes.
Ruby on Rails Overview (Beginner Summary)
[Ruby on Rails] Read try (: [],: key)
[Ruby on Rails] yarn install --check-files
Spring Boot + PostgreSQL error resolution method
Ruby on Rails variable, constant summary
Installing Ruby + Rails on Ubuntu 18.04 (rbenv)
[Ruby on Rails] Introduced paging function
Basic knowledge of Ruby on Rails
Progate Ruby on Rails5 Looking Back
How to use Ruby on Rails
[Ruby on Rails] Add / Remove Columns
Ruby on Rails Japanese-English support i18n
(Ruby on Rails6) "Erase" posted content
[Ruby on Rails] CSV output function
Ruby on Rails 6.0 environment construction memo
[Ruby on Rails] What is Bcrypt?
[Ruby on Rails] Confirmation page creation