Upload
sky-wang
View
183
Download
0
Embed Size (px)
Citation preview
Rails vs Node.js2015.09.17
Sky
FB: jcsky.wangRuby on Rails: 6 months
Node.js: 1 week / 1 project
WHY~?!
• Ruby on Rails: AlphaCamp ihower
• Node.js: front-end interview (javascript, full-stack)
Rails vs Node.jsRuby
Rails
Rails server engine / event driven gem
include many many
CRUD / DataBase / safe
sync
javascript
express / koa / sails ..
node.js
npm any you want
speed / realtime / anyway you want
async
Rails vs Node.js
Node.js is not framework.. express / koa / hapi / sails
Rails vs Node.js• javascript Debug (chrome console )
Rails vs Node.js• Node.js server log Debug
Rails error
Rails vs Node.js• Rails console debug
Rails vs Node.js• Rails method database code
• : DB
• : DataBase
Event.joins(:category) # SELECT "events".* FROM "events" INNER JOIN "categories" ON "categories"."id" = "events"."category_id"
Event.includes(:category, :attendees) # SELECT "events".* FROM "events" # SELECT "categories".* FROM "categories" WHERE "categories"."id" IN (1,2,3...) # SELECT "attendees".* FROM "attendees" WHERE "attendees"."event_id" IN (4, 5, 6, 7, 8...)
Rails vs Node.js• not only Ruby, numerous Rails helper method
html <%= render :partial => 'form', :locals => { :f => f } %>
form <%= form_for @event, :url => { :controller => 'events', :action => 'update', :id => @event } do |f| %> <%= f.textarea :description, :class=>”w100p”, :rows =>10 %> <%= f.submit "Update" %> <% end %>
controller method before_action :set_event, :only => [ :show, :edit, :update, :destroy]
session read/write session[:hahaha]
Rails vs Node.js• Rails have some Security Design ( )
CSRF(Cross-site request forgery) Rails CSRF POST
HTML: <input type="hidden" name="authenticity_token" value="zFGT+TiykMj7Tsip3sY5G7iELupGD3BttZ8x6F2diThGOVH9+nEoXxkeLOhuLx9kGaWRoOhZuwY+OXzXU3EevA==">
Parameters: {"utf8"=>"✓", "authenticity_token"=>"HC4eVH/wdojRqSJFk8xYdobZPByVTFkh2WiCbK6HYb+WRtxQvTPOHzP5xgQjJX4JJ/iDVjsakkpSzs9ToGv2Ow==", "issue"=>{"title"=>"yaya", "description"=>"what the fuck"}, "commit"=>" "}
Rails vs Node.js• Rails have some Security Design( )
XSS(Cross-Site Scripting) Script
<script><script> Rails
HTML
Rails vs Node.js• Rails have some Security Design( )
log ( )
Processing UsersController#create (for 127.0.0.1 at 2009-01-02 11:02:33) [POST] Parameters: {"user"=>{"name"=>"susan", "password_confirmation"=>"[FILTERED]", "password"=>"[FILTERED]"}, "commit"=>"Register", "action"=>"create", "authenticity_token"=>"9efc03bcc37191d8a6dc3676e2e7890ecdfda0b5", "controller"=>"users"}
Ruby vs javascript
gem vs npm• ~?!! npm.count !!
Rails introMVC
Model-View-Control
route.rbHTTP requestGET /users/1
Browser
UsersController
end
def show@user = User.find(params[:id])
respond_to do |format|format.htmlformat.xml
endend
def index......
end
Model
Database
#show.html.erb
<html> <h1>User Profile</h1> <p><%= @user.nickname %></p></html>
View
t�¶�² Controller � Action
���U�1�0¤þ!
Rails introRails XR©ăVĴ?
• Justin Gehtland ü9 Java :Rails = 3.5 : 1
• Proc.net ü9 PHP : Rails = 10 : 1
• JavaEye Å�b JAVA : Rails = 10 : 1
• thegiive ĞŘ�ą� PHP : Rails = 8 : 1
���U�1�0¤þ!
Rails vs Node.jsRuby
Rails
Rails server engine / event driven gem
include many many
CRUD / DataBase / safe
javascript
express / koa / sails ..
node.js
npm any you want
speed / realtime / anyway you want
in the future
Real Time App / Web
theword.twFB: www.facebook.com/theword.tw
vs
(..)
…()
~!!