Environment Related:
First, the order:
1. Update the installed version of rails: Gem update rails
2, after the updated version of Rails automatically save the previous version of the file upgrade, using the Gem Cleanup command to delete these files
3. After installing the latest version of Rails, use the rake rails:update command to join new rails at the beginning of the creation of the application
Of those files
4, create the project
Switch to the appropriate directory and enter the command "Rails new project Name"
5, start the server command Rails s/rails Server stop service: CTRL + C
Start Webrick server: Rails server Webrick
In the case of a 64-bit operating system, the sqlite3 version of "Gemfile.lock" in the project root directory is to be run before running
Change from "x86" to "x64"
6, create a controllers class: Rails G Controller "class name"
For example: Create a Welcome controller class: Rails g Controller Welcome
You can also use the rails generate command
For example: Create a Say controller class: the name of the controller we want to create and we qualify this controller branch
The name of the action passed past: Rails generate controller Say Hello World
Under the console, enter the rails generate controller Say Hello Goodbye command, where Say is the name of the controller class to be generated,
Hello and goodbye are two actions in the Controller class, and the rails framework creates a SAY_CONTROLLER.RB in the project's controllers directory
The file represents the controller class and generates Hello.html.erb and Goobbye.html.erb two files in the project's Views/say directory, both
The file is identical to the command parameters entered by the command line. Note: The rails framework will automatically look for the actions in the controller to find the View/say directory and the action name
The same. html.erb file
7, if you do not want to run the program immediately, but first check that the program is correct, then enter the RUBY-C command
For example: Ruby-c test.rb #检查当前目录下的test. rb file for errors
RUBY-CW: Check the syntax of the program but not execute
8. The console lists all directories using DIR (Windows), LS (Linux)
Rails4.0.2 Summary
1, create the project
Switch to the appropriate directory and enter the command "Rails new project Name"
2, start the server rails s
Stop service: CTRL + C
3. The $ $ in Ruby represents the current script file: For example, the current file name is "TEST.RB" and is printed in the current file puts
$, the result of the output is the full path name of the current file
4. Ruby Data type
(1) Integer type
1) 2 of the 30 Fixnum is the type of the following
2) 2 of the 30-time bignum is the type of
(2) String: string
(3) Floating-point number type: float
(4) Boolean type False:falseclass type; True:trueclass type
(5) NULL type Nil:nilclass type
(6) class type: Class
5. Data type Conversion
(1) integer turn string _info = 5.to_s;
(2) string rounding _info = "Hello". to_i;
6, console output
Puts: Default line break print: Default no wrap printf: Default no newline p output ASCII code
7 Console input
Gets: Accept a string from the console: _info = gets;
8. Set access gates for members of type (equivalent to get, set method in Java)
For example: Class MyInfo
@name;
Attr_reader:name #相当于get方法
Attr_writer:name #相当于set方法
Attr_accessor:name #相当于get和set方法
7, variables and constants
The member variable begins with the @, the global variable starts with $, and the static variable begins with the @@ 开头 in uppercase.
9. Operators in Ruby
(1) The powers in Ruby are expressed as "5", i.e. 3 _info = 5; Puts _info**3;
(2) = = = Range of comparison
(3) <==>: compare two worthy sizes
Returns 1 if the previous value is less than the following value, and returns 1 if the previous value is greater than the following value
Returns 0 if two values are equal
For example: 5<=>5--->0 5<=>4---->1 5<=>6---->-1
10, the scope of Ruby
Class Test
_info = 1..5; #1到5之间包括5, _info=1...5 does not include 5
Puts _info.max; #输出最大值5
Puts _info.min; #输出最小值1
Puts _info.end; #输出最后一个值5
End