Ruby on Rails - Ruby on Rails Scripts - ruby on rails tutorial - rails guides - rails tutorial - ruby rails
What is a Scripts?
- A script or scripting language is a computer language with a series of commands within a file that is capable of being executed without being compiled.
Types of scripts in Ruby on Rails:
- Ruby on Rails gives valuable scripts, which you use during your project implementation.
- Now few scripts which you will utilize most frequently.
Script | Description |
---|---|
script/about | Gives information about environment. |
script/breakpointer | Starts the breakpoint server. |
script/console | Interactive Rails Console. |
script/destroy | Deletes files created by generators. |
script/generate | Used by generators. |
script/runner | Executes a task in the rails context. |
script/server | Launches the development server. |
script/performance/profile | Profiles an expansive method. |
script/performance/benchmarker | Benchmarks different methods. |
Script Example
- Following script will start development server.
C:\ruby> ruby script/server
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
C:\ruby> ruby script/server
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Running Rails Scripts
- RubyMine permits to execute Rails scripts using a single menu command.
- RubyMine suggests the scripts that reside in the [
]/script directory of your Rails application. - Results for each script are displayed in its own Run Rails Script tab of the Run tool window, where you can evaluation the script output, change arguments if necessary, and rerun the script.
ruby on rails tutorial tags - ruby , rail , ruby on rails , rail forum , ruby on rails tutorial , ruby tutorial , rails guides , rails tutorial , learn ruby
To run a Rails script
Step 1:
- On the main menu, choose Tools | Run Rails Script. Run Rails Script dialog box is displayed.
Step 2:
- In the Script field, specify the desired script. If the script resides in the [
]/script directory, type its name only. If the script resides in another directory, type its fully qualified name.
Step 3:
- Alternatively, click the browse button .(Shift+Enter) and select the necessary location in the dialog that opens . Note that this dialog displays only the contents of the [
]/script directory.
![learn ruby on rails tutorial - ruby run rails script - ruby on rails example](https://wikitechy.com/tutorials/ruby-on-rails/img/ruby-on-rails-images/ruby_runRailsScript.png)
learn ruby on rails tutorial - ruby run rails script - ruby on rails example
Step 4:
- In the Arguments field, specify the script's arguments, if any. The arguments should be separated with spaces. Alternatively, open the Edit Arguments dialog box by clicking the editor button , or pressing Shift+Enter, and type the list of arguments.
Step 5:
- Click Run.
To rerun a Rails script with new arguments
Step 1:
- In the Run tool window, click the desired Run Rails Script tab.
Step 2:
- In the toolbar of the Run tool window, click /help/img/idea/2017.2/editArguments.png. Edit Command Line Arguments dialog box is displayed.
ruby on rails tutorial tags - ruby , rail , ruby on rails , rail forum , ruby on rails tutorial , ruby tutorial , rails guides , rails tutorial , learn ruby
Step 3:
- In the Edit Command Line Arguments dialog box, type the new arguments separated with spaces, and click OK.
Step 4:
- In the toolbar of the Run tool window, click , or press Ctrl+F5
Rails scripts used in Rails application:
- Rails gives us outstanding tools that are used to develop Rails application.
- These tools are packaged as scripts from command line.
- Rails Console
- WEBrick Web Server
- Generators
- Migrations
Rails Console
- The Rails console is as command line usefulness which runs Rails application from the command line.
- The Rails console is an extension of Ruby irb.
- It provides all the features of irb along with the ability to auto-load Rails application environment, including all its classes and components.
- It helps you to walk through your application step-by-step.
![learn ruby on rails tutorial - action cable - ruby on rails example](https://wikitechy.com/tutorials/ruby-on-rails/img/ruby-on-rails-images/action-cable.gif)
learn ruby on rails tutorial - action cable - ruby on rails example
WEBrick Web server
- Rails is configured to automatically use WEBrick server.
- This server is written in pure Ruby and supports almost all platforms like Windows, Mac or Unix.
- Alternatively, if you have Mongrel or lighttpd server installed in your system, Rails uses either of those servers.
![learn ruby on rails tutorial - web server - ruby on rails example](https://wikitechy.com/tutorials/ruby-on-rails/img/ruby-on-rails-images/web-server.png)
learn ruby on rails tutorial - web server - ruby on rails example
- All the three Rails servers feature automatic reloading of code. It means, when you change your source code, you do not need to restart the server.
Generators
- The Rails include code generation scripts, which are used to automatically generate model and controller classes for an application.
- Code generation increases your productivity when developing Web applications.
- By running generator command, skeleton files for all your model and controller classes will be generated.
- It also generates, database migration files for each model it generates.
![learn ruby on rails tutorial - rails2generate - ruby on rails example](https://wikitechy.com/tutorials/ruby-on-rails/img/ruby-on-rails-images/rails2generate.png)
learn ruby on rails tutorial - rails2generate - ruby on rails example
Migrations
- Migrations bring Rails DRY feature to life.
- It is a pure Ruby code that define the structure of a database.
- You don't have to use SQL to write your code while using migration.
- The changes you make to your database schema is isolated in a separate migration file, which has a method to implement or reverse the change.