├── .gitignore
├── Gemfile
├── Gemfile.lock
├── README.md
├── Rakefile
├── app
├── controllers
│ ├── application_controller.rb
│ └── notes_controller.rb
└── models
│ ├── .keep
│ └── note.rb
├── bin
├── bundle
├── rails
└── rake
├── config.ru
├── config
├── application.rb
├── boot.rb
├── database.yml
├── environment.rb
├── environments
│ ├── development.rb
│ ├── production.rb
│ └── test.rb
├── initializers
│ ├── backtrace_silencers.rb
│ ├── filter_parameter_logging.rb
│ ├── inflections.rb
│ ├── mime_types.rb
│ ├── secret_token.rb
│ ├── session_store.rb
│ └── wrap_parameters.rb
├── locales
│ └── en.yml
└── routes.rb
├── db
├── migrate
│ └── 20130723050253_create_notes.rb
├── schema.rb
└── seeds.rb
├── doc
└── layout.jpg
├── log
└── .keep
└── ngapp
├── .bowerrc
├── .editorconfig
├── .gitattributes
├── .gitignore
├── .jshintrc
├── Gruntfile.js
├── app
├── .buildignore
├── .htaccess
├── 404.html
├── favicon.ico
├── index.html
├── robots.txt
├── scripts
│ ├── app.js
│ └── controllers
│ │ └── main.js
├── styles
│ ├── bootstrap.css
│ └── main.css
└── views
│ └── main.html
├── bower.json
├── karma-e2e.conf.js
├── karma.conf.js
├── libpeerconnection.log
├── package.json
└── test
├── runner.html
└── spec
└── controllers
└── main.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 | #
3 | # If you find yourself ignoring temporary files generated by your text editor
4 | # or operating system, you probably want to add a global ignore instead:
5 | # git config --global core.excludesfile '~/.gitignore_global'
6 |
7 | # Ignore bundler config.
8 | /.bundle
9 |
10 | # Ignore the default SQLite database.
11 | /db/*.sqlite3
12 | /db/*.sqlite3-journal
13 |
14 | # Ignore all logfiles and tempfiles.
15 | /log/*.log
16 | /tmp
17 |
18 | public/
19 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | gem 'rails', '4.0.0'
4 |
5 | # Heroku stuff
6 | gem 'rails_12factor', group: :production
7 | gem 'pg'
8 | gem 'sqlite3'
9 |
10 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
11 | gem 'jbuilder', '~> 1.2'
12 |
--------------------------------------------------------------------------------
/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 | actionmailer (4.0.0)
5 | actionpack (= 4.0.0)
6 | mail (~> 2.5.3)
7 | actionpack (4.0.0)
8 | activesupport (= 4.0.0)
9 | builder (~> 3.1.0)
10 | erubis (~> 2.7.0)
11 | rack (~> 1.5.2)
12 | rack-test (~> 0.6.2)
13 | activemodel (4.0.0)
14 | activesupport (= 4.0.0)
15 | builder (~> 3.1.0)
16 | activerecord (4.0.0)
17 | activemodel (= 4.0.0)
18 | activerecord-deprecated_finders (~> 1.0.2)
19 | activesupport (= 4.0.0)
20 | arel (~> 4.0.0)
21 | activerecord-deprecated_finders (1.0.3)
22 | activesupport (4.0.0)
23 | i18n (~> 0.6, >= 0.6.4)
24 | minitest (~> 4.2)
25 | multi_json (~> 1.3)
26 | thread_safe (~> 0.1)
27 | tzinfo (~> 0.3.37)
28 | arel (4.0.0)
29 | atomic (1.1.10)
30 | builder (3.1.4)
31 | erubis (2.7.0)
32 | hike (1.2.3)
33 | i18n (0.6.4)
34 | jbuilder (1.4.2)
35 | activesupport (>= 3.0.0)
36 | multi_json (>= 1.2.0)
37 | mail (2.5.4)
38 | mime-types (~> 1.16)
39 | treetop (~> 1.4.8)
40 | mime-types (1.23)
41 | minitest (4.7.5)
42 | multi_json (1.7.7)
43 | pg (0.16.0)
44 | polyglot (0.3.3)
45 | rack (1.5.2)
46 | rack-test (0.6.2)
47 | rack (>= 1.0)
48 | rails (4.0.0)
49 | actionmailer (= 4.0.0)
50 | actionpack (= 4.0.0)
51 | activerecord (= 4.0.0)
52 | activesupport (= 4.0.0)
53 | bundler (>= 1.3.0, < 2.0)
54 | railties (= 4.0.0)
55 | sprockets-rails (~> 2.0.0)
56 | rails_12factor (0.0.2)
57 | rails_serve_static_assets
58 | rails_stdout_logging
59 | rails_serve_static_assets (0.0.1)
60 | rails_stdout_logging (0.0.1)
61 | railties (4.0.0)
62 | actionpack (= 4.0.0)
63 | activesupport (= 4.0.0)
64 | rake (>= 0.8.7)
65 | thor (>= 0.18.1, < 2.0)
66 | rake (10.1.0)
67 | sprockets (2.10.0)
68 | hike (~> 1.2)
69 | multi_json (~> 1.0)
70 | rack (~> 1.0)
71 | tilt (~> 1.1, != 1.3.0)
72 | sprockets-rails (2.0.0)
73 | actionpack (>= 3.0)
74 | activesupport (>= 3.0)
75 | sprockets (~> 2.8)
76 | sqlite3 (1.3.7)
77 | thor (0.18.1)
78 | thread_safe (0.1.0)
79 | atomic
80 | tilt (1.4.1)
81 | treetop (1.4.14)
82 | polyglot
83 | polyglot (>= 0.3.1)
84 | tzinfo (0.3.37)
85 |
86 | PLATFORMS
87 | ruby
88 |
89 | DEPENDENCIES
90 | jbuilder (~> 1.2)
91 | pg
92 | rails (= 4.0.0)
93 | rails_12factor
94 | sqlite3
95 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | A sample [AngularJS](http://angularjs.org)
2 | [app](https://github.com/EmmanuelOga/simple-angular-rails-app/)
3 | which uses [rails](http://rubyonrails.org/) as a backend.
4 |
5 | * [The running app](http://morning-chamber-9005.herokuapp.com/#/) on all its glory.
6 | * Github [repository](https://github.com/EmmanuelOga/simple-angular-rails-app/).
7 |
8 | While it is possible to include AngularJS as part of the rails assets, I
9 | think it is better to setup the angular code base on a
10 | standalone folder, leaving the rails app as a (more or less)
11 | isolated backend.
12 |
13 | There are several advantages to this setup:
14 |
15 | * Ability to manage the frontend app using
16 | [Yeoman](http://yeoman.io/)
17 | (including [generators](https://github.com/yeoman/generator-angular#readme)!).
18 | * No more questions about file layout: use rails layout for rails stuff,
19 | angular-generator layout for angular stuff.
20 | * Easily install external assets via [bower](http://bower.io/) (e.g.
21 | angularjs, jquery, twitter bootstrap, underscore, etc.).
22 | * Write client side unit tests and run them with
23 | [karma](http://karma-runner.github.com).
24 | * Promotes unit-testing the js codebase and removes the temptation of
25 | integration-testing everything: testing with karma is a lot faster
26 | than using capybara or a similar solution.
27 | * [LiveReload](http://livereload.com/) support for free with yeoman's
28 | angular generator! (uses websockets, no need to install a browser plugin).
29 |
30 | ## Yeoman, Bower, Livereload and Karma Runner.
31 |
32 | I want to stress out the convinience of working on your frontend using
33 | the stack yeoman sets up for you. By keeping the frontend isolated from
34 | the backend you get an amazingly fast development environment and draw a
35 | clear line between backend and frontend (great for making sure you are
36 | writing the right unit/integration tests).
37 | Yeoman sets up the test environment for you using jasmine as the testing
38 | library and karma as the runner. karma is possibly the [fastest and most
39 | complete js test runner](http://www.youtube.com/watch?feature=player_detailpage&v=Mb3_oT8ZreI&t=11) out
40 | there. And it is very well integrated with angular.
41 |
42 |
43 |
44 | The experience of coding with Livereload is simply amazing. Immediate
45 | feedback for every little addition you save in your code editor while
46 | you are working, without having to reload the page in the browser!
47 |
48 | True: you can [use livereload with rails](https://github.com/guard/guard-livereload) alone, and you
49 | can [use bower with rails too](http://dev.af83.com/2013/01/02/managing-rails-assets-with-bower.html).
50 | But Yeoman's angular generator sets everything right for you with a
51 | single command.
52 |
53 | Rails was born in the request-response era of web applications, and it
54 | shows. Yeoman sets up a web environment with defaults that are better
55 | suited for developing web applications.
56 |
57 | ## Setting the environment up
58 |
59 | You'll need:
60 |
61 | * ruby 1.9.3 ([rvm](https://rvm.io/) recommended for installation)
62 | * node 0.10.13 ([nvm](https://github.com/creationix/nvm) recommended for installation)
63 | * Two shell sessions!
64 |
65 | ### Session one: the rails backend:
66 |
67 | ```
68 | rvm use 1.9.3
69 | git clone https://github.com/EmmanuelOga/simple-angular-rails-app.git
70 | cd simple-angular-rails-app
71 | bundle install
72 | bundle exec rails s -p 3000
73 | ```
74 |
75 | **NOTE**: the angular application was generated using these commands.
76 |
77 | ```
78 | npm install -g yo generator-angular
79 | mkdir ngapp; cd ngapp
80 | yo angular notes
81 | ```
82 |
83 | ### Session two: a grunt server
84 |
85 | ```
86 | nvm use 0.10.13
87 | cd simple-angular-rails-app/ngapp
88 | npm install -g grunt-cli
89 | npm install
90 | bower install
91 | grunt server # opens a browser window... you are done!
92 | ```
93 |
94 | ## What's going on?
95 |
96 | During development, you need to run both the rails app and the grunt
97 | server. The reason is the html client was written as if the rails
98 | backend was an isolated, independent service, using
99 | [Yeoman](http://yeoman.io/) to scaffold the project.
100 |
101 | The intent is to **simulate** that the whole environment is a single web
102 | application. An, indeed, before deploying to prod we'll be consolidating
103 | the whole angular app as static assets in rails' public/ folder.
104 |
105 | Here's a diagram of the stack during development:
106 |
107 | 
108 |
109 | The grunt server task
110 | [proxies](http://github.com/EmmanuelOga/simple-angular-rails-app/blob/master/ngapp/Gruntfile.js#L65-L71)
111 | any url with path /api to the rails backend on localhost:3000.
112 |
113 | Rails is used in the backend, but really any web framework would be ok
114 | here ([sinatra](http://www.sinatrarb.com/) would make a lot more sense
115 | for my silly example app!).
116 |
117 | ## TESTING
118 |
119 | To run both the backend tests and front end tests, you can run:
120 |
121 | ```
122 | rake test PHANTOMJS_BIN=`which phantomjs`
123 | ```
124 |
125 | This is done by [reopening rails's test
126 | task](https://github.com/EmmanuelOga/simple-angular-rails-app/blob/master/Rakefile#L8-L10)
127 | and adding a step to run the karma runner. This design is a bit
128 | simplistic but it works. You may want to have something a bit more
129 | elaborate to make it so angular's tests are run even if rails tests fail
130 | to complete.
131 |
132 | The PHANTOMJS_BIN env var is needed because the project configures karma
133 | to use [phantom js](http://www.phantomjs.org), but it could be changed
134 | to run any other browser.
135 |
136 | karma can be
137 | [configured](https://github.com/EmmanuelOga/simple-angular-rails-app/blob/master/ngapp/karma.conf.js#L40)
138 | to watch the tests as opposed to do a single run. You should
139 | deffinitively look into that during development.
140 |
141 | ## Deploying
142 |
143 | If you run `grunt build`, grunt will package the whole angular app in a
144 | tidy package on the rails public/ folder. This packaging step could
145 | happen in the server to avoid having to commit the generated assets in
146 | your repository, analogous to how it is done for generating assets with
147 | rails' assets pipeline.
148 |
149 | ## XSRF support
150 |
151 | The rails app sets the XSRF token in the cookies. The cookies are
152 | accessible even when using the proxy because the port is [not taken into
153 | account](http://stackoverflow.com/questions/1612177/are-http-cookies-port-specific)
154 | when restricting access to the cookies.
155 |
156 | Check
157 | [ApplicationController](http://github.com/EmmanuelOga/simple-angular-rails-app/blob/master/app/controllers/application_controller.rb)
158 | for some notes on the XSRF protection.
159 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | # Add your own tasks in files placed in lib/tasks ending in .rake,
2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3 |
4 | require File.expand_path('../config/application', __FILE__)
5 |
6 | Testapp::Application.load_tasks
7 |
8 | task :test do
9 | system("cd ngapp; grunt test")
10 | end
11 |
--------------------------------------------------------------------------------
/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 | # Prevent CSRF attacks by raising an exception.
3 | # For APIs, you may want to use :null_session instead.
4 | protect_from_forgery with: :exception
5 |
6 | after_filter :set_csrf_cookie_for_ng
7 |
8 | def ping
9 | render text: "Rails Backend 1.0"
10 | end
11 |
12 | private
13 |
14 | #http://stackoverflow.com/questions/14734243/rails-csrf-protection-angular-js-protect-from-forgery-makes-me-to-log-out-on
15 | def set_csrf_cookie_for_ng
16 | cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery?
17 | end
18 |
19 | def verified_request?
20 | super || form_authenticity_token == request.headers['HTTP_X_XSRF_TOKEN']
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/app/controllers/notes_controller.rb:
--------------------------------------------------------------------------------
1 | class NotesController < ApplicationController
2 | before_action :set_note, only: [:show, :update, :destroy]
3 |
4 | # GET /notes.json
5 | def index
6 | render json: Note.all
7 | end
8 |
9 | # GET /notes/1.json
10 | def show
11 | end
12 |
13 | # POST /notes.json
14 | def create
15 | @note = Note.new(note_params)
16 |
17 | if @note.save
18 | render json: @note, status: :ok
19 | else
20 | render json: @note.errors, status: :unprocessable_entity
21 | end
22 | end
23 |
24 | # PATCH/PUT /notes/1.json
25 | def update
26 | if @note.update(note_params)
27 | head :no_content
28 | else
29 | render json: @note.errors, status: :unprocessable_entity
30 | end
31 | end
32 |
33 | # DELETE /notes/1.json
34 | def destroy
35 | @note.destroy
36 | head :no_content
37 | end
38 |
39 | private
40 | # Use callbacks to share common setup or constraints between actions.
41 | def set_note
42 | @note = Note.find(params[:id])
43 | end
44 |
45 | # Never trust parameters from the scary internet, only allow the white list through.
46 | def note_params
47 | params.permit(:title, :body)
48 | end
49 | end
50 |
--------------------------------------------------------------------------------
/app/models/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EmmanuelOga/simple-angular-rails-app/3562ecb7d86ab2b3bfda2fb1ce69f085f0e88f97/app/models/.keep
--------------------------------------------------------------------------------
/app/models/note.rb:
--------------------------------------------------------------------------------
1 | class Note < ActiveRecord::Base
2 | end
3 |
--------------------------------------------------------------------------------
/bin/bundle:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3 | load Gem.bin_path('bundler', 'bundle')
4 |
--------------------------------------------------------------------------------
/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | APP_PATH = File.expand_path('../../config/application', __FILE__)
3 | require_relative '../config/boot'
4 | require 'rails/commands'
5 |
--------------------------------------------------------------------------------
/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require_relative '../config/boot'
3 | require 'rake'
4 | Rake.application.run
5 |
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require ::File.expand_path('../config/environment', __FILE__)
4 | run Rails.application
5 |
--------------------------------------------------------------------------------
/config/application.rb:
--------------------------------------------------------------------------------
1 | require File.expand_path('../boot', __FILE__)
2 |
3 | require 'rails/all'
4 |
5 | # Require the gems listed in Gemfile, including any gems
6 | # you've limited to :test, :development, or :production.
7 | Bundler.require(:default, Rails.env)
8 |
9 | module Testapp
10 | class Application < Rails::Application
11 | # Settings in config/environments/* take precedence over those specified here.
12 | # Application configuration should go into files in config/initializers
13 | # -- all .rb files in that directory are automatically loaded.
14 |
15 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
16 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
17 | # config.time_zone = 'Central Time (US & Canada)'
18 |
19 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
20 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
21 | # config.i18n.default_locale = :de
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/config/boot.rb:
--------------------------------------------------------------------------------
1 | # Set up gems listed in the Gemfile.
2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3 |
4 | require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
5 |
--------------------------------------------------------------------------------
/config/database.yml:
--------------------------------------------------------------------------------
1 | # SQLite version 3.x
2 | # gem install sqlite3
3 | #
4 | # Ensure the SQLite 3 gem is defined in your Gemfile
5 | # gem 'sqlite3'
6 | development:
7 | adapter: sqlite3
8 | database: db/development.sqlite3
9 | pool: 5
10 | timeout: 5000
11 |
12 | # Warning: The database defined as "test" will be erased and
13 | # re-generated from your development database when you run "rake".
14 | # Do not set this db to the same as development or production.
15 | test:
16 | adapter: sqlite3
17 | database: db/test.sqlite3
18 | pool: 5
19 | timeout: 5000
20 |
21 | production:
22 | adapter: sqlite3
23 | database: db/production.sqlite3
24 | pool: 5
25 | timeout: 5000
26 |
--------------------------------------------------------------------------------
/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the Rails application.
2 | require File.expand_path('../application', __FILE__)
3 |
4 | # Initialize the Rails application.
5 | Testapp::Application.initialize!
6 |
--------------------------------------------------------------------------------
/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | Testapp::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # In the development environment your application's code is reloaded on
5 | # every request. This slows down response time but is perfect for development
6 | # since you don't have to restart the web server when you make code changes.
7 | config.cache_classes = false
8 |
9 | # Do not eager load code on boot.
10 | config.eager_load = false
11 |
12 | # Show full error reports and disable caching.
13 | config.consider_all_requests_local = true
14 | config.action_controller.perform_caching = false
15 |
16 | # Don't care if the mailer can't send.
17 | config.action_mailer.raise_delivery_errors = false
18 |
19 | # Print deprecation notices to the Rails logger.
20 | config.active_support.deprecation = :log
21 |
22 | # Raise an error on page load if there are pending migrations
23 | config.active_record.migration_error = :page_load
24 |
25 | # Debug mode disables concatenation and preprocessing of assets.
26 | # This option may cause significant delays in view rendering with a large
27 | # number of complex assets.
28 | config.assets.debug = true
29 | end
30 |
--------------------------------------------------------------------------------
/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | Testapp::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # Code is not reloaded between requests.
5 | config.cache_classes = true
6 |
7 | # Eager load code on boot. This eager loads most of Rails and
8 | # your application in memory, allowing both thread web servers
9 | # and those relying on copy on write to perform better.
10 | # Rake tasks automatically ignore this option for performance.
11 | config.eager_load = true
12 |
13 | # Full error reports are disabled and caching is turned on.
14 | config.consider_all_requests_local = false
15 | config.action_controller.perform_caching = true
16 |
17 | # Enable Rack::Cache to put a simple HTTP cache in front of your application
18 | # Add `rack-cache` to your Gemfile before enabling this.
19 | # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
20 | # config.action_dispatch.rack_cache = true
21 |
22 | # Disable Rails's static asset server (Apache or nginx will already do this).
23 | config.serve_static_assets = false
24 |
25 | # Compress JavaScripts and CSS.
26 | config.assets.js_compressor = :uglifier
27 | # config.assets.css_compressor = :sass
28 |
29 | # Do not fallback to assets pipeline if a precompiled asset is missed.
30 | config.assets.compile = false
31 |
32 | # Generate digests for assets URLs.
33 | config.assets.digest = true
34 |
35 | # Version of your assets, change this if you want to expire all your assets.
36 | config.assets.version = '1.0'
37 |
38 | # Specifies the header that your server uses for sending files.
39 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
40 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
41 |
42 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
43 | # config.force_ssl = true
44 |
45 | # Set to :debug to see everything in the log.
46 | config.log_level = :info
47 |
48 | # Prepend all log lines with the following tags.
49 | # config.log_tags = [ :subdomain, :uuid ]
50 |
51 | # Use a different logger for distributed setups.
52 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
53 |
54 | # Use a different cache store in production.
55 | # config.cache_store = :mem_cache_store
56 |
57 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
58 | # config.action_controller.asset_host = "http://assets.example.com"
59 |
60 | # Precompile additional assets.
61 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
62 | # config.assets.precompile += %w( search.js )
63 |
64 | # Ignore bad email addresses and do not raise email delivery errors.
65 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
66 | # config.action_mailer.raise_delivery_errors = false
67 |
68 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
69 | # the I18n.default_locale when a translation can not be found).
70 | config.i18n.fallbacks = true
71 |
72 | # Send deprecation notices to registered listeners.
73 | config.active_support.deprecation = :notify
74 |
75 | # Disable automatic flushing of the log to improve performance.
76 | # config.autoflush_log = false
77 |
78 | # Use default logging formatter so that PID and timestamp are not suppressed.
79 | config.log_formatter = ::Logger::Formatter.new
80 | end
81 |
--------------------------------------------------------------------------------
/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | Testapp::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # The test environment is used exclusively to run your application's
5 | # test suite. You never need to work with it otherwise. Remember that
6 | # your test database is "scratch space" for the test suite and is wiped
7 | # and recreated between test runs. Don't rely on the data there!
8 | config.cache_classes = true
9 |
10 | # Do not eager load code on boot. This avoids loading your whole application
11 | # just for the purpose of running a single test. If you are using a tool that
12 | # preloads Rails for running tests, you may have to set it to true.
13 | config.eager_load = false
14 |
15 | # Configure static asset server for tests with Cache-Control for performance.
16 | config.serve_static_assets = true
17 | config.static_cache_control = "public, max-age=3600"
18 |
19 | # Show full error reports and disable caching.
20 | config.consider_all_requests_local = true
21 | config.action_controller.perform_caching = false
22 |
23 | # Raise exceptions instead of rendering exception templates.
24 | config.action_dispatch.show_exceptions = false
25 |
26 | # Disable request forgery protection in test environment.
27 | config.action_controller.allow_forgery_protection = false
28 |
29 | # Tell Action Mailer not to deliver emails to the real world.
30 | # The :test delivery method accumulates sent emails in the
31 | # ActionMailer::Base.deliveries array.
32 | config.action_mailer.delivery_method = :test
33 |
34 | # Print deprecation notices to the stderr.
35 | config.active_support.deprecation = :stderr
36 | end
37 |
--------------------------------------------------------------------------------
/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/config/initializers/filter_parameter_logging.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Configure sensitive parameters which will be filtered from the log file.
4 | Rails.application.config.filter_parameters += [:password]
5 |
--------------------------------------------------------------------------------
/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format. Inflections
4 | # are locale specific, and you may define rules for as many different
5 | # locales as you wish. All of these examples are active by default:
6 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
7 | # inflect.plural /^(ox)$/i, '\1en'
8 | # inflect.singular /^(ox)en/i, '\1'
9 | # inflect.irregular 'person', 'people'
10 | # inflect.uncountable %w( fish sheep )
11 | # end
12 |
13 | # These inflection rules are supported but not enabled by default:
14 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
15 | # inflect.acronym 'RESTful'
16 | # end
17 |
--------------------------------------------------------------------------------
/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new mime types for use in respond_to blocks:
4 | # Mime::Type.register "text/richtext", :rtf
5 | # Mime::Type.register_alias "text/html", :iphone
6 |
--------------------------------------------------------------------------------
/config/initializers/secret_token.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Your secret key is used for verifying the integrity of signed cookies.
4 | # If you change this key, all old signed cookies will become invalid!
5 |
6 | # Make sure the secret is at least 30 characters and all random,
7 | # no regular words or you'll be exposed to dictionary attacks.
8 | # You can use `rake secret` to generate a secure secret key.
9 |
10 | # Make sure your secret_key_base is kept private
11 | # if you're sharing your code publicly.
12 | Testapp::Application.config.secret_key_base = '4a8f13b352158d3d4ebccde17859378b55fb77d2dd288727c21d7a814b200ddcef64997a7c4aad99959293e6d376c761b0bb58274493e8a403f3f8873e28e59d'
13 |
--------------------------------------------------------------------------------
/config/initializers/session_store.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 | Testapp::Application.config.session_store :cookie_store, key: '_testapp_session'
3 |
--------------------------------------------------------------------------------
/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # This file contains settings for ActionController::ParamsWrapper which
4 | # is enabled by default.
5 |
6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7 | ActiveSupport.on_load(:action_controller) do
8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9 | end
10 |
11 | # To enable root element in JSON for ActiveRecord objects.
12 | # ActiveSupport.on_load(:active_record) do
13 | # self.include_root_in_json = true
14 | # end
15 |
--------------------------------------------------------------------------------
/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Files in the config/locales directory are used for internationalization
2 | # and are automatically loaded by Rails. If you want to use locales other
3 | # than English, add the necessary files in this directory.
4 | #
5 | # To use the locales, use `I18n.t`:
6 | #
7 | # I18n.t 'hello'
8 | #
9 | # In views, this is aliased to just `t`:
10 | #
11 | # <%= t('hello') %>
12 | #
13 | # To use a different locale, set it with `I18n.locale`:
14 | #
15 | # I18n.locale = :es
16 | #
17 | # This would use the information in config/locales/es.yml.
18 | #
19 | # To learn more, please read the Rails Internationalization guide
20 | # available at http://guides.rubyonrails.org/i18n.html.
21 |
22 | en:
23 | hello: "Hello world"
24 |
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | Testapp::Application.routes.draw do
2 |
3 | get "api/ping" => "application#ping"
4 |
5 | resources :notes, path: 'api/notes'
6 |
7 | end
8 |
--------------------------------------------------------------------------------
/db/migrate/20130723050253_create_notes.rb:
--------------------------------------------------------------------------------
1 | class CreateNotes < ActiveRecord::Migration
2 | def change
3 | create_table :notes do |t|
4 | t.string :title
5 | t.text :body
6 |
7 | t.timestamps
8 | end
9 | end
10 | end
11 |
--------------------------------------------------------------------------------
/db/schema.rb:
--------------------------------------------------------------------------------
1 | # encoding: UTF-8
2 | # This file is auto-generated from the current state of the database. Instead
3 | # of editing this file, please use the migrations feature of Active Record to
4 | # incrementally modify your database, and then regenerate this schema definition.
5 | #
6 | # Note that this schema.rb definition is the authoritative source for your
7 | # database schema. If you need to create the application database on another
8 | # system, you should be using db:schema:load, not running all the migrations
9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10 | # you'll amass, the slower it'll run and the greater likelihood for issues).
11 | #
12 | # It's strongly recommended that you check this file into your version control system.
13 |
14 | ActiveRecord::Schema.define(version: 20130723050253) do
15 |
16 | create_table "notes", force: true do |t|
17 | t.string "title"
18 | t.text "body"
19 | t.datetime "created_at"
20 | t.datetime "updated_at"
21 | end
22 |
23 | end
24 |
--------------------------------------------------------------------------------
/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # This file should contain all the record creation needed to seed the database with its default values.
2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3 | #
4 | # Examples:
5 | #
6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7 | # Mayor.create(name: 'Emanuel', city: cities.first)
8 |
--------------------------------------------------------------------------------
/doc/layout.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EmmanuelOga/simple-angular-rails-app/3562ecb7d86ab2b3bfda2fb1ce69f085f0e88f97/doc/layout.jpg
--------------------------------------------------------------------------------
/log/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EmmanuelOga/simple-angular-rails-app/3562ecb7d86ab2b3bfda2fb1ce69f085f0e88f97/log/.keep
--------------------------------------------------------------------------------
/ngapp/.bowerrc:
--------------------------------------------------------------------------------
1 | {
2 | "directory": "app/bower_components"
3 | }
4 |
--------------------------------------------------------------------------------
/ngapp/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 |
8 | [*]
9 |
10 | # Change these settings to your own preference
11 | indent_style = space
12 | indent_size = 2
13 |
14 | # We recommend you to keep these unchanged
15 | end_of_line = lf
16 | charset = utf-8
17 | trim_trailing_whitespace = true
18 | insert_final_newline = true
19 |
20 | [*.md]
21 | trim_trailing_whitespace = false
22 |
--------------------------------------------------------------------------------
/ngapp/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
--------------------------------------------------------------------------------
/ngapp/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | .tmp
4 | .sass-cache
5 | app/bower_components
6 |
--------------------------------------------------------------------------------
/ngapp/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "node": true,
3 | "browser": true,
4 | "esnext": true,
5 | "bitwise": true,
6 | "camelcase": true,
7 | "curly": true,
8 | "eqeqeq": true,
9 | "immed": true,
10 | "indent": 2,
11 | "latedef": true,
12 | "newcap": true,
13 | "noarg": true,
14 | "quotmark": "single",
15 | "regexp": true,
16 | "undef": true,
17 | "unused": true,
18 | "strict": true,
19 | "trailing": true,
20 | "smarttabs": true,
21 | "globals": {
22 | "angular": false
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/ngapp/Gruntfile.js:
--------------------------------------------------------------------------------
1 | // Generated on 2013-07-21 using generator-angular 0.3.0
2 | 'use strict';
3 | var LIVERELOAD_PORT = 35729;
4 | var lrSnippet = require('connect-livereload')({ port: LIVERELOAD_PORT });
5 | var mountFolder = function (connect, dir) {
6 | return connect.static(require('path').resolve(dir));
7 | };
8 | var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;
9 |
10 | // # Globbing
11 | // for performance reasons we're only matching one level down:
12 | // 'test/spec/{,*/}*.js'
13 | // use this if you want to recursively match all subfolders:
14 | // 'test/spec/**/*.js'
15 | //
16 | /* jshint indent: false */
17 |
18 | module.exports = function (grunt) {
19 | // load all grunt tasks
20 | require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
21 |
22 | // load the proxy.
23 | grunt.loadNpmTasks('grunt-connect-proxy');
24 |
25 | // configurable paths
26 | var yeomanConfig = {
27 | app: 'app',
28 | dist: '../public'
29 | };
30 |
31 | try {
32 | yeomanConfig.app = require('./bower.json').appPath || yeomanConfig.app;
33 | } catch (e) {}
34 |
35 | grunt.initConfig({
36 | yeoman: yeomanConfig,
37 | watch: {
38 | coffee: {
39 | files: ['<%= yeoman.app %>/scripts/{,*/}*.coffee'],
40 | tasks: ['coffee:dist']
41 | },
42 | coffeeTest: {
43 | files: ['test/spec/{,*/}*.coffee'],
44 | tasks: ['coffee:test']
45 | },
46 | livereload: {
47 | options: {
48 | livereload: LIVERELOAD_PORT
49 | },
50 | files: [
51 | '<%= yeoman.app %>/{,*/}*.html',
52 | '{.tmp,<%= yeoman.app %>}/styles/{,*/}*.css',
53 | '{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js',
54 | '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
55 | ]
56 | }
57 | },
58 | connect: {
59 | options: {
60 | port: 9000,
61 | // Change this to '0.0.0.0' to access the server from outside.
62 | hostname: 'localhost'
63 | },
64 | proxies: [
65 | {
66 | context: '/api',
67 | host: 'localhost',
68 | port: 3000
69 | }
70 | ],
71 | livereload: {
72 | options: {
73 | middleware: function (connect) {
74 | return [
75 | proxySnippet,
76 | lrSnippet,
77 | mountFolder(connect, '.tmp'),
78 | mountFolder(connect, yeomanConfig.app)
79 | ];
80 | }
81 | }
82 | },
83 | test: {
84 | options: {
85 | middleware: function (connect) {
86 | return [
87 | mountFolder(connect, '.tmp'),
88 | mountFolder(connect, 'test')
89 | ];
90 | }
91 | }
92 | },
93 | dist: {
94 | options: {
95 | middleware: function (connect) {
96 | return [
97 | mountFolder(connect, yeomanConfig.dist)
98 | ];
99 | }
100 | }
101 | }
102 | },
103 | open: {
104 | server: {
105 | url: 'http://localhost:<%= connect.options.port %>'
106 | }
107 | },
108 | clean: {
109 | dist: {
110 | files: [{
111 | dot: true,
112 | src: [
113 | '.tmp',
114 | '<%= yeoman.dist %>/*',
115 | '!<%= yeoman.dist %>/.git*'
116 | ]
117 | }]
118 | },
119 | server: '.tmp'
120 | },
121 | jshint: {
122 | options: {
123 | jshintrc: '.jshintrc'
124 | },
125 | all: [
126 | 'Gruntfile.js',
127 | '<%= yeoman.app %>/scripts/{,*/}*.js'
128 | ]
129 | },
130 | coffee: {
131 | dist: {
132 | files: [{
133 | expand: true,
134 | cwd: '<%= yeoman.app %>/scripts',
135 | src: '{,*/}*.coffee',
136 | dest: '.tmp/scripts',
137 | ext: '.js'
138 | }]
139 | },
140 | test: {
141 | files: [{
142 | expand: true,
143 | cwd: 'test/spec',
144 | src: '{,*/}*.coffee',
145 | dest: '.tmp/spec',
146 | ext: '.js'
147 | }]
148 | }
149 | },
150 | // not used since Uglify task does concat,
151 | // but still available if needed
152 | /*concat: {
153 | dist: {}
154 | },*/
155 | rev: {
156 | dist: {
157 | files: {
158 | src: [
159 | '<%= yeoman.dist %>/scripts/{,*/}*.js',
160 | '<%= yeoman.dist %>/styles/{,*/}*.css',
161 | '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
162 | '<%= yeoman.dist %>/styles/fonts/*'
163 | ]
164 | }
165 | }
166 | },
167 | useminPrepare: {
168 | html: '<%= yeoman.app %>/index.html',
169 | options: {
170 | dest: '<%= yeoman.dist %>'
171 | }
172 | },
173 | usemin: {
174 | html: ['<%= yeoman.dist %>/{,*/}*.html'],
175 | css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
176 | options: {
177 | dirs: ['<%= yeoman.dist %>']
178 | }
179 | },
180 | imagemin: {
181 | dist: {
182 | files: [{
183 | expand: true,
184 | cwd: '<%= yeoman.app %>/images',
185 | src: '{,*/}*.{png,jpg,jpeg}',
186 | dest: '<%= yeoman.dist %>/images'
187 | }]
188 | }
189 | },
190 | cssmin: {
191 | // By default, your `index.html` will take care of
192 | // minification. This option is pre-configured if you do not wish to use
193 | // Usemin blocks.
194 | // dist: {
195 | // files: {
196 | // '<%= yeoman.dist %>/styles/main.css': [
197 | // '.tmp/styles/{,*/}*.css',
198 | // '<%= yeoman.app %>/styles/{,*/}*.css'
199 | // ]
200 | // }
201 | // }
202 | },
203 | htmlmin: {
204 | dist: {
205 | options: {
206 | /*removeCommentsFromCDATA: true,
207 | // https://github.com/yeoman/grunt-usemin/issues/44
208 | //collapseWhitespace: true,
209 | collapseBooleanAttributes: true,
210 | removeAttributeQuotes: true,
211 | removeRedundantAttributes: true,
212 | useShortDoctype: true,
213 | removeEmptyAttributes: true,
214 | removeOptionalTags: true*/
215 | },
216 | files: [{
217 | expand: true,
218 | cwd: '<%= yeoman.app %>',
219 | src: ['*.html', 'views/*.html'],
220 | dest: '<%= yeoman.dist %>'
221 | }]
222 | }
223 | },
224 | // Put files not handled in other tasks here
225 | copy: {
226 | dist: {
227 | files: [{
228 | expand: true,
229 | dot: true,
230 | cwd: '<%= yeoman.app %>',
231 | dest: '<%= yeoman.dist %>',
232 | src: [
233 | '*.{ico,png,txt}',
234 | '.htaccess',
235 | 'bower_components/**/*',
236 | 'images/{,*/}*.{gif,webp,svg}',
237 | 'styles/fonts/*'
238 | ]
239 | }, {
240 | expand: true,
241 | cwd: '.tmp/images',
242 | dest: '<%= yeoman.dist %>/images',
243 | src: [
244 | 'generated/*'
245 | ]
246 | }]
247 | }
248 | },
249 | concurrent: {
250 | server: [
251 | 'coffee:dist'
252 | ],
253 | test: [
254 | 'coffee'
255 | ],
256 | dist: [
257 | 'coffee',
258 | 'imagemin',
259 | 'htmlmin'
260 | ]
261 | },
262 | karma: {
263 | unit: {
264 | configFile: 'karma.conf.js',
265 | singleRun: true
266 | }
267 | },
268 | cdnify: {
269 | dist: {
270 | html: ['<%= yeoman.dist %>/*.html']
271 | }
272 | },
273 | ngmin: {
274 | dist: {
275 | files: [{
276 | expand: true,
277 | cwd: '<%= yeoman.dist %>/scripts',
278 | src: '*.js',
279 | dest: '<%= yeoman.dist %>/scripts'
280 | }]
281 | }
282 | },
283 | uglify: {
284 | dist: {
285 | files: {
286 | '<%= yeoman.dist %>/scripts/scripts.js': [
287 | '<%= yeoman.dist %>/scripts/scripts.js'
288 | ]
289 | }
290 | }
291 | }
292 | });
293 |
294 | grunt.registerTask('server', function (target) {
295 | if (target === 'dist') {
296 | return grunt.task.run(['build', 'open', 'connect:dist:keepalive']);
297 | }
298 |
299 | grunt.task.run([
300 | 'clean:server',
301 | 'concurrent:server',
302 | 'configureProxies',
303 | 'connect:livereload',
304 | 'open',
305 | 'watch'
306 | ]);
307 | });
308 |
309 | grunt.registerTask('test', [
310 | 'clean:server',
311 | 'concurrent:test',
312 | 'configureProxies',
313 | 'connect:test',
314 | 'karma'
315 | ]);
316 |
317 | grunt.registerTask('build', [
318 | 'clean:dist',
319 | 'useminPrepare',
320 | 'concurrent:dist',
321 | 'concat',
322 | 'copy',
323 | 'cdnify',
324 | 'ngmin',
325 | 'cssmin',
326 | 'uglify',
327 | 'rev',
328 | 'usemin'
329 | ]);
330 |
331 | grunt.registerTask('default', [
332 | 'jshint',
333 | 'test',
334 | 'build'
335 | ]);
336 | };
337 |
--------------------------------------------------------------------------------
/ngapp/app/.buildignore:
--------------------------------------------------------------------------------
1 | *.coffee
--------------------------------------------------------------------------------
/ngapp/app/.htaccess:
--------------------------------------------------------------------------------
1 | # Apache Configuration File
2 |
3 | # (!) Using `.htaccess` files slows down Apache, therefore, if you have access
4 | # to the main server config file (usually called `httpd.conf`), you should add
5 | # this logic there: http://httpd.apache.org/docs/current/howto/htaccess.html.
6 |
7 | # ##############################################################################
8 | # # CROSS-ORIGIN RESOURCE SHARING (CORS) #
9 | # ##############################################################################
10 |
11 | # ------------------------------------------------------------------------------
12 | # | Cross-domain AJAX requests |
13 | # ------------------------------------------------------------------------------
14 |
15 | # Enable cross-origin AJAX requests.
16 | # http://code.google.com/p/html5security/wiki/CrossOriginRequestSecurity
17 | # http://enable-cors.org/
18 |
19 | #
Sorry, but the page you were trying to view does not exist.
146 |It looks like this was the result of either:
147 |{{note.body}}
19 |