Ruby on Rails Study Notes

Source: Internet
Author: User
Tags ruby on rails

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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.