If i mistakenly enter a number in full-width in the url as shown below, flash [: danger] = "Please make id half-width"
How can I get a message?
http: // localhost: 3000/users/7/edit
↓ It is the controller of the corresponding part
* It is set as before_action on edit and show pages.
def set_user @user = User.find (params [: id]) if @ user.id == @ user.id.to_s flash [: danger] = "Please make id half-width" end end
* Currently, such an error is appearing.
Answer # 1
In the current code, DB search is performed with the ID that is full-width, so an error has occurred because User data could not be acquired.
So, before that, convert the specified ID (params [: id]) to half-width and use the half-width ID to perform User.find ().
However, even in that case, an ActiveRecord :: RecordNotFound exception may occur, so take corrective action.
Only when an exception does not occur, if the specified ID and the acquired User id do not match, an error will be notified.
We're sorry, but please create the code yourself.
- ruby - about the matter that the error message at the time of "rails" validation check is not displayed
- ruby on rails - i get an error in a program that changes over time
- ruby on rails - i want to improve rails name error
- ruby on rails 6 - i want to solve the error that occurred while implementing the product listing function
- ruby - an error occurs when building a rails 6 environment with docker
- ruby - the error in rails g migration cannot be resolved
- ruby on rails - i get an error without being created
- ruby on rails 6 - [error] uninitialized constant user (call'userconnection' to establish a connection) :: image
- ruby on rails - i want to resolve rails name error
- ruby on rails - nomethoderror in itemscontroller # new error
- ruby on rails - unknown action error when trying to post a comment
- ruby on rails - rails routing error
- ruby on rails - syntax error cannot be resolved
- ruby - [rails] i want to be able to enter only double-byte characters including symbols in validation
- ruby on rails - i get a template is missing error in render
- ruby on rails - i want to download a file with rails, s3 and carrierwave, but i get an error
- ruby on rails - i want to put what i posted on the show page, but it's a blank page it's not an error
- error in building environment of ruby on rails
- ruby - when i try to update rails, i get a routing error
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to call a child component method from a parent in vuejs
- i want to check the type of a shell script variable