Reference books: Agile web development with rails 4th Edition
Create a new website and create some default directories and files:
$ Rails new <projectname>
Start the server and run the following command in the project directory:
$ Rails Server
Default website address: http: // localhost: 3000/
Generate controller for two pages
$ Rails generate controller controllername page1 page2
In the. html. ERB fileCodeIt is Ruby.
@ Variable: Variable
The link can be linked in standard HTML.
<A href = "/say/Hello"> Hello </a>
However, if the file location changes in the future, the URL may become invalid. The rails solution should be used:
<% = Link_to "goodbye", say_goodbye_path %>
Config/routes. RB: configure the ing between the browser path and the file. For example, you can access http: // localhost: 3000/and use root to use a file as the default file.
Root: To => 'store # Index',: As => 'store'
: String is the symbol, saving memory than the string, because the symbol is saved only once.
Ruby's special foreach expression. The brackets are actually blocks. | contains local variables representing each member:
Array. Each {| localvariable | print localvariable}
Rubyonrails, learning notes