Skip to content

Instantly share code, notes, and snippets.

@uguisu-an
Created May 24, 2014 05:54
Show Gist options
  • Select an option

  • Save uguisu-an/dcb4644a8f74f41c4d5f to your computer and use it in GitHub Desktop.

Select an option

Save uguisu-an/dcb4644a8f74f41c4d5f to your computer and use it in GitHub Desktop.
rails template for angularjs
gem 'angularjs-rails'
run_bundle
inside 'config/environments' do
gsub_file 'production.rb',
/config.assets.js_compressor = :uglifier/,
"config.assets.js_compressor = Uglifier.new(mangle: false)"
end
inside 'app/assets/javascripts' do
insert_into_file 'application.js', <<-CODE, before: "//= require_tree ."
//= require angular
//= require angular-resource
//= require angular_app
CODE
file 'angular_app.js.coffee', <<-CODE
@angularApp = angular.module('angularApp', ['ngResource'])
@angularApp.config ($httpProvider) ->
authToken = $("meta[name=\\"csrf-token\\"]").attr("content")
$httpProvider.defaults.headers.common["X-CSRF-TOKEN"] = authToken
$(document).on 'page:load', ->
$('[ng-app]').each ->
module = $(this).attr('ng-app')
angular.bootstrap(this, [module])
CODE
file 'controllers/.keep'
file 'directives/.keep'
file 'services/.keep'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment