Rails is a language particularly known for its rapid development and shortcut commands that make development of applications and its modules fast and easy. Today I am going to tell you about few most basic commands of rails:
1. rails new:
This command is the first command for rails that is used for creating applications in Ruby on Rails. Once you hit this command it creates a full fledged rails application with full structured rails app.
This command starts the WEBrick server that starts the application. By default it runs the application on port number 3000 in development mode. you can change the port number and mode by providing it with -p [For port number] and -e [For environment]. The syntax for this is
It will give output like:
=> Booting WEBrick
=> Rails 220.127.116.11 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-06-02 15:21:21] INFO WEBrick 1.3.1
[2016-06-02 15:21:21] INFO ruby 2.2.1 (2015-02-26) [x86_64-linux]
[2016-06-02 15:21:21] INFO WEBrick::HTTPServer#start: pid=8143 port=3000
## For running app with port number and environment you can run this command like:
rails server -p PORT_NUMBER -e ENVIRONMENT
3. rails generate:
This is the command that acts as a generator for creating different types of files in Ruby on Rails application like Models, Controllers etc.
rails generate GENERATOR [args] [options]
To generate a model use the following:
rails generate model ModelName column:datatype column:datatype [...]
$ rails g model User name:string email:string
Running via Spring preloader in process 10196
$ rails g controller users
Running via Spring preloader in process 10237
4. rails console:
This command lets you interact with the application and its database through console. It is very helpful in debugging the application. Application methods can also be called from this console.
$ rails c
Running via Spring preloader in process 10313
Loading development environment (Rails 18.104.22.168)
2.2.1 :001 >
5. rails destroy:
This command is used for destroying the things already generated using rails command like if you have generated model User using rails g then you can remove it using rails d.
$ rails g model User
Running via Spring preloader in process 10509
$ rails d model User
Running via Spring preloader in process 10529
Hope you enjoyed reading this. Will talk about some more command line features of rails soon.