Ruby on Rails notes"/>
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: ModelModel: REACT
MVC Framework expects you to put
Model stuff in Model classes,
Controller stuff in Controller class,
View stuff in View classesRails 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 BREADoperation
* 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 doresources :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 doresources :comments, shallow: true
end
更多推荐
LHL Ruby on Rails notes
发布评论