Creating rails route manually take time and typo is not allowed. All file names and locations are specific. It is a small challenge for developers. It is very easy to make a mistake and broke the application.
That’s why generators is important. Generator will create all required files on behalf of developer. It is auto generated so, no longer need to worries about naming convention and location of the file.
Different types of generators:
- Model : generate a model and migration file. syntax:
rails g model <Name of Model> attributes :string is default --no-test-framework
- Controller: will just generate controller
- Migration: generate a new migration
- Resource : generate all of above and view directory without view file and optionally routes
- Syntax:
rails g <name of generator> <options> --no-test-framework
The keyword params
comes from ActionController::Base
params
refers to the parameters being passed to the controller via a GET or POST request.
In GET request params
get passed to the controller from the URL in the user’s browser.
def self.find_by_name
self.find(params[:name])
end
If rake server command comes back with Runtime error, check with Postman if the localhost is running in background.
To kill the localhost type following command in Terminal
$ lsof -wni tcp:<Port number>
Noted PID from the list and type following command in Terminal
$ kill -9 <PID>
Or not sure the port number is running? Type below command on terminal
ps -ax | grep puma
Note the PID number with the running localhost project and kill it.
Done.
If there is this ‘You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.0)’ error when using command below.
npx creat-react-app app-name
Method 1. Clear npx cache with following command
npx clear-npx-cache
Method 2. Force using latest npx
npx create-react-app@latest_version my-app --use-npm
Method 3.
% npm uninstall -g create-react-app
% npm cache clean --force
% npx create-react-app my-app