
Ruby
SimonHeeeee
这个作者很懒,什么都没留下…
展开
-
Ruby on Rails testing using rspec
Testing# Gemfilegroup :development, :test do gem 1 gem 2 gem 3endgroup :development do gem 4 gem 5 gem 6end# spec folder# rails_helper.rb# spec_helper.rb# model folder# name_spec.rb# features folder# names_spec.rb# in m原创 2020-11-15 02:10:06 · 181 阅读 · 0 评论 -
Ruby Or Equal Operator: ||=
Conditional Assignment Operatora ||= nil # => nila ||= 0 # => 0a ||= 2 # => 0If a is undefined or false, the assign b to a, otherwise do nothing原创 2020-11-13 12:42:56 · 112 阅读 · 0 评论 -
Ruby on Rails: Nested Resources Demo
rails new nestedResourcesDemorails g scaffold User username:string passwrod_hash:stringrails g scaffold Post user:references title:string content:text# user.rbhas_many :post# post.rbbelongs_to :userrails db migraterails c@user = User.create原创 2020-11-13 12:38:43 · 130 阅读 · 0 评论 -
Ruby on Rails: Form and Authentication 表以及用户登陆与退出
FormThe destination urlWhether the data is associated with a modelThe field namesThe field input typesThe display name of fieldsWith URL:<%= form_with url: '/login' do |form| %> <%= form.label :email %> <%= form.原创 2020-11-13 12:37:07 · 165 阅读 · 0 评论 -
Rails server error: server is already running
server is already running.Solution: kill the serverkill -9 $(lsof -i tcp:3000 -t)原创 2020-11-11 22:38:58 · 305 阅读 · 0 评论 -
Ruby on Rails: database relations and common errors 数据库关系建立以及常见问题
One-to-many and Many-to-many relationshipsrails g scaffold Department code:string name:stringrails g scaffold Course department:references code:integer title:string description:textrails db:migraterails g scaffold User first_name:string last_name:st原创 2020-11-11 10:33:52 · 177 阅读 · 0 评论 -
Ruby: Scaffold Generator, AREL, Validation, One-to-many, Many-to-many
Scaffold GeneratorIt generates:Model/migrationcontoller file and implementationthe entire view folderall restful routesrails new blogDemonstrationcd blogDemonstration/rails g scaffold Post title:string content:textrails d scaffold Post# in原创 2020-10-26 05:49:34 · 158 阅读 · 0 评论 -
Ruby on Rails Blog Project 创建博客网站项目
Blog projectSet up projectrails new Blog --db=postgresqlcd Blograils s -b 0.0.0.0# localhost:3000Home Pageget '/pages', to: 'pages#home' in routes.rbCreate pages_controller.rb in controllers folderclass PagesController < ApplicationControl原创 2020-10-18 12:31:00 · 192 阅读 · 0 评论 -
Ruby: Arel and Forms
Data typesstringtextintegerfloatdecimaldatetimetimestamptimedatebooleanreferencesSQL -> ORM -> Arel# Common commandsUser.where(name: 'Simon')User.find_by(name: 'Simon')User.limit(2)User.order(id: :desc)# Chaining commandsPost.wh原创 2020-10-17 22:47:29 · 133 阅读 · 0 评论 -
Ruby: Rails basic structure creation and debugging Rails项目的编写与调试
RailsFundamental Rail Commands:rails new PROJECT_NAME # creat eall filesrails s -b 0.0.0.0 # boots up server, listen for request on port 3000Route -> Controller -> Viewdefine routeshandler methods in controllerwrite view templates in the原创 2020-10-11 02:48:25 · 156 阅读 · 0 评论 -
Ruby: Rails structure and naming convention Rails结构与命名规则
Content:LogicIntroductionConventionsRuby on Rails Logic*Browser* <--request/response--> *Server* --request_info--> *Routing* ^ | | Params + Methods | | HTML + Assets V原创 2020-10-10 23:03:38 · 164 阅读 · 0 评论 -
Network Layers 网络层介绍
Network4 networking layerslink layer: physical mediadirection connections between machinespacket-basedinternet layerwho do I want to talk to?Internet Protocol (IP) addressIPv4 (32-bit) and IPv6 (128-bit)how do I get messages to/from them原创 2020-10-04 02:49:39 · 367 阅读 · 0 评论 -
Ruby: Object-Oriented-Programming 面向对象编程
OOPTable of contentsClass declarationInstance variables and methodsConstructor method initializeInstance variables and Instance MethodsReader/Writer methodsOther instance mtehodsClass variables and Class methodsPrivate methodsDescribing metho原创 2020-09-20 23:20:23 · 161 阅读 · 0 评论 -
Ruby: Basic Syntax 基础语法
Ruby BasicsRuby is strongly typed and dynamically typedirb # run in command lineibj = object.newobj.classobj.class.superclassobj.methodsfoo = 5# Print string# "#{var}"p "Hello, #{foo}!"# Orp 'Hello, ' + foo.to_s + '!'def obj:talk(message,原创 2020-09-20 21:55:26 · 157 阅读 · 0 评论