LHL Ruby on Rails notes

Ruby
The methods need to know for Arrays in Ruby all rhyme
select is ‘filter’ in javascript
collect is ‘map’ in javascript
inject is ‘reduce’ in javascript
detect is ‘find’ in javascript
reject is not in Javascript

Ruby on Rails

* MVC Frameworks (Model- View - Controller)
    * Ruby on Rails 
    * ASP.NET MVC (C#)
    * Django ( Python)
    * Codeigniter (PHP)

Route Handler style (Middleware)
    * Legacy PHP
    * Express
    * Sinatra (Ruby)
    Hanami (Ruby)

Three buckets of code: 

* Providing an interface: view

* Performing Business Logic: controler
    * Example: Tinyapp `POST` `/urls`
    * Redirect if not logged in 
    * If logged in, get user from session
    * Data integrity check (400- clinet error)
    * Save url to database
    * Return the created url(201) / redirect to `GET` `/urls`

* Querying and Modifying Data Stores: Model

Model: REACT
MVC Framework expects you to put 
Model stuff in Model classes, 
Controller stuff in Controller class, 
View stuff in View classes

Rails is great at 20% of web server techniques used in 80% of the situation.
very opinionated:
* You are trying to make an HTTP server
* Your app logic can be sorted into resources, onto which you will perform BREAD
  operation 
* It's better to have a buch of built in functionality
* 
gem install rails
oop - Object-Oriented Programig
rails console - this will create a repl in cmd you could do CRUD
rails dbconsole - it will use SQLITE for the database

2.7.2 Shallow Nesting
One way to avoid deep nesting is to generate the collection actions scoped under the parent, so as to get a sense of the hierarchy, but to not nest the member actions. In other words, to only build routes with the minimal amount of information to uniquely identify the resource, like this:

resources :articles do
  resources :comments, only: [:index, :new, :create]
end
resources :comments, only: [:show, :edit, :update, :destroy]

This idea strikes a balance between descriptive routes and deep nesting. There exists shorthand syntax to achieve just that, via the :shallow option:

resources :articles do
  resources :comments, shallow: true
end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值