Node.js for Ruby on Rails Developers

Platform

Ruby on Rails

Node.js

Tools

Ruby on Rails

Node.js

CoffeeScript

number = 42
number = -42 if opposite

square = (x) -> x * x

list = [1, 2, 3, 4, 5]

math =
  root:   Math.sqrt
  square: square
  cube:   (x) -> x * square x

race = (winner, runners...) ->
  print winner, runners

alert "I knew it!" if elvis?

cubes = (math.cube num for num in list)

Testing

Ruby on Rails

Node.js

Conventions

Ruby

JavaScript

Routing in Ruby on Rails

match "/posts/:id" => "posts#show"

resources :post

resources :post, :only => [:index, :show]

resources :post do
  resources :comments
end

namespace :admin do
  resources :post
end

Routing in Node.js

map.get "posts/:id", "posts#show"

map.resources "posts"

map.resources "posts", only: ['index', 'show']

map.resources 'post', (post) ->
  post.resources 'comments'


namespace 'admin', (admin) ->
  admin.resources 'posts'

ORM

ActiveRecord

JugglingDB

Controllers

Ruby on Rails

def show
  flash[:error] = "Can't find any posts."
  redirect 'http://www.google.com'
  #render
end

Node.js

action 'index', ->
  flash 'error', "Can't find any posts."
  redirect 'http://www.google.com'
  render()

Views

link_to('Users index', '/users', {class: 'menu-item'});

form_for(user, {action: path_to.users}, function (form) {
  form.label('name', 'Username')
  form.input('name')
  form.submit('Save')
});

stylesheet_link_tag('reset', 'style')

javascript_include_tag(
  'https://some.cdn.com/jquery.min.js',
  'application')

Generators

[railway|rails] generate (generator)

Custom Setup

Your Turn!

Create a Blog with Railway

About

Sean Massa

Resources

#

/