Angular + Rails

made easy

Pawel Pierzchala @zwrozka

sckrk
powow
angular
rails

Separation

Frontend and backend are independed applications

Communication

Through an API

Tips & Tricks

Security #1


$httpProvider.defaults.xsrfCookieName = 'X-CSRF-Token'
$httpProvider.defaults.xsrfHeaderName = 'X-CSRF-Token'
          

cookies['X-CSRF-Token'] = form_authenticity_token
          

Security #2


PREFIX = ")]}',\n"

def render_json(data)
  json = PREFIX + data.as_json
  render text: text, content_type: "application/json"
end
          

JSON conventions


{ userName: 'Joe' } == { :user_name => 'Joe' }
          

HTML files in assets pipeline

Testing in Ruby

API request specs / unit tests

Testing in JavaScript

Unit tests with Karma

Acceptance tests

In Capybara

end to end (api)

A word on Angular guts

angular loop

Without any race conditons in pure angular

Almost no problmes with JavaScripts from ngmodules.org

Old Capybara tricks as fallback

Mock api

Record & Playback

Summary

independed applications

stable e2e tests

links

Thanks