├── template.rb └── README.md /template.rb: -------------------------------------------------------------------------------- 1 | # This script is used with the Ruby on Rails' new project generator: 2 | # 3 | # rails new my_app -m path/to/this/template.rb 4 | # 5 | # For more information about the template API, see: 6 | # http://edgeguides.rubyonrails.org/rails_application_templates.html 7 | # 8 | # this template assumes: 9 | # 10 | # npm installed 11 | # npm install -g bower 12 | # npm install -g ember-cli 13 | 14 | # Install required gems 15 | gem "active_model_serializers" 16 | 17 | # kill un-needed gems 18 | run "sed -i.bck '/turbolinks/d' Gemfile" 19 | run "sed -i.bck '/coffee/d' Gemfile" 20 | run "sed -i.bck '/jbuilder/d' Gemfile" 21 | run "sed -i.bck '/jquery-rails/d' Gemfile" 22 | 23 | run "bundle install" 24 | 25 | # cleanup 26 | run "rm Gemfile.bck" 27 | 28 | ember_app = "#{@app_name}-ember" 29 | 30 | # create ember-cli app 31 | run "ember new #{ember_app}" 32 | run "cd #{ember_app} && npm link ember-cli" 33 | 34 | #don't track node_modules via git 35 | run "echo '/#{ember_app}/node_modules/*' >> .gitignore" 36 | 37 | # build rails catch-all route 38 | route "get '*path' => redirect('/')" 39 | 40 | generate :serializer, "application", "--parent", "ActiveModel::Serializer" 41 | inject_into_class "app/serializers/application_serializer.rb", "ApplicationSerializer" do 42 | " embed :ids, :include => true\n" 43 | end 44 | 45 | #create build.sh from template put in bin/ 46 | template_dir = File.expand_path(File.dirname(__FILE__)) 47 | build_file_path = template_dir + "/build.sh.erb" 48 | template = File.open(build_file_path, "rb") {|io| io.read} 49 | 50 | build_content = ERB.new(template).result(binding) 51 | File.open('bin/build.sh', 'w') { |file| file.write(build_content) } 52 | run "chmod a+x bin/build.sh" 53 | 54 | puts <<-MESSAGE 55 | 56 | *********************************************************** 57 | 58 | Your ember-cli app is located at: '#{@app_path}/#{ember_app}' 59 | see: https://github.com/stefanpenner/ember-cli 60 | 61 | To build the ember project for deployment run 62 | 63 | `./bin/build.sh` 64 | 65 | *********************************************************** 66 | 67 | MESSAGE 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ember-cli-rails 2 | 3 | A rails template and build script for working with [ember-cli](https://github.com/stefanpenner/ember-cli) 4 | and deploying with a rails api / backend. The goal is to allow ember-cli to be 5 | in charge of building and testing your ember app, and rails to be in charge of 6 | building and testing your rails app. 7 | 8 | 9 | ## Dependencies 10 | 11 | You will need the usual dev setup ruby, rails, bundler, node && npm. Once you 12 | have those, you will also need `bower` and `ember-cli` 13 | 14 | install `bower` via npm 15 | 16 | ```bash 17 | $ npm install -g bower 18 | ``` 19 | 20 | install `ember-cli` via npm 21 | 22 | ```bash 23 | $ npm install -g ember-cli 24 | ``` 25 | 26 | ## Usage 27 | 28 | clone the repo 29 | 30 | ```bash 31 | $ git clone git@github.com:knomedia/ember-cli-rails.git 32 | ``` 33 | 34 | Assuming you are in the same directory as the `ember-cli-rails` repo, create a 35 | new rails app like: 36 | 37 | ```bash 38 | $ rails new app -m ember-cli-rails/template.rb 39 | ``` 40 | 41 | If you are in another location, change the path to the template file as needed. 42 | 43 | You now have a rails project with an ember-cli project within it. 44 | 45 | The template will set a catch-all rails route that serves up the ember app. 46 | **You'll need to update your ember app config to set `location: 'hash'` manually 47 | for this to work.** As you add api endpoints to rails be sure to place them 48 | before the catch all route. 49 | 50 | ## Daily development 51 | 52 | To work on the project, cd into the project root and: 53 | 54 | ```bash 55 | $ bin/rails s 56 | ``` 57 | 58 | In another tab cd into your ember app (it'll be inside the rails root and 59 | labled with your app-name-ember). From within the ember-app directory run the 60 | development ember server 61 | 62 | ```bash 63 | $ ember serve --proxy http://localhost:3000 64 | ``` 65 | 66 | This will proxy api calls to your rails backend. For more information see the 67 | [ember-cli docs](http://iamstef.net/ember-cli/) 68 | 69 | 70 | ## Deployment 71 | 72 | From time to time, or whenever time to deploy, cd to your rails root and run: 73 | 74 | ```bash 75 | $ ./bin/build.sh 76 | ``` 77 | 78 | This will utilize `ember-cli` to build your ember app, and copy files over to 79 | your rails `public/` directory. 80 | --------------------------------------------------------------------------------