[Ruby] Ruby on Rails Basics Memorandum of Understanding

1 minute read

Ruby on Rails Memorandum

I am studying the basics of Ruby on Rails, so I will leave it as a memo so that I can learn it myself.

What is Ruby on Rails?

A web application framework written in Ruby. MVC (Model, View, Controller) model is adopted. In order to reduce the burden on the programmer, the necessary items are prepared in advance in the framework. There are two basic principles: “Don’t Repeat Yourself” and “Convention over Cofiguration”.

Create new application

rails new application name

A folder with the application name is created

Start server

rails server

Automatic creation of top page

rails generate controller home (controller name) top (action name)

Three elements are created when you automatically create the top page

・View The part to see. Web html It is stored in the views folder. The file extension is erb

・Controller Invokes an “action” in Ruby and returns html to the browser. Returns the html with the same name as the action from the view folder with the same name in the controller. In other words, a postman who receives a postcard and delivers the postcard to the recipient.

・Routing So to speak, it enters between the browser and the controller and does traffic maintenance. This url is the place to write your sort to this controller. The routing is described by url => controller name#action name.

In automatic creation, create the top page view + controller, Add the route of controller name#action name.

View file (extension .erb)

erb means Embedded Ruby Use <% %> when embedding the ruby code in the file.


<% posts.each do |post| %>
<% end %>

If you want to display the code in the browser, use <%= %>.

to be continued···

Tags: ,