Created
September 23, 2013 22:18
-
-
Save pixelhandler/6677757 to your computer and use it in GitHub Desktop.
Source to complete tutorial at http://hashrocket.com/blog/posts/setting-up-an-ember-app-with-a-rails-backend I used ember-data-canary and ember-canary versions to get the data to work
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #app/assets/javascripts/app.js.coffee | |
| #= require ./store | |
| #= require_tree ./models | |
| #= require_tree ./controllers | |
| #= require_tree ./views | |
| #= require_tree ./helpers | |
| #= require_tree ./templates | |
| #= require_tree ./routes | |
| #= require ./router | |
| #= require_self |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <% # app/views/layouts/application.html.erb %> | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Launchbay</title> | |
| <%= stylesheet_link_tag "application", media: "all" %> | |
| <%= javascript_include_tag "application" %> | |
| <%= csrf_meta_tags %> | |
| </head> | |
| <body> | |
| <%= yield %> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -#app/views/application.html.haml | |
| !!! | |
| %html(lang="en-US") | |
| %head | |
| %title Launch Bay | |
| = stylesheet_link_tag "application" | |
| = javascript_include_tag "application" | |
| = csrf_meta_tags | |
| %body | |
| = yield |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // app/assets/javascripts/application.js | |
| // This is a manifest file that'll be compiled into application.js, which will include all the files | |
| // listed below. | |
| // | |
| // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, | |
| // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. | |
| // | |
| // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the | |
| // compiled file. | |
| // | |
| // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details | |
| // about supported directives. | |
| // | |
| //= require jquery-1.9.1 | |
| //= require jquery_ujs | |
| //= require handlebars-1.0.0 | |
| //= require ember-canary | |
| //= require ember-data-canary | |
| //= require_self | |
| //= require app | |
| // for more details see: http://emberjs.com/guides/application/ | |
| App = Ember.Application.create(); | |
| //= require_tree . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #config/database.yml | |
| # PostgreSQL. Versions 8.2 and up are supported. | |
| development: | |
| adapter: postgresql | |
| encoding: unicode | |
| database: launchbay_development | |
| pool: 5 | |
| username: postgres | |
| password: | |
| test: | |
| adapter: postgresql | |
| encoding: unicode | |
| database: launchbay_test | |
| pool: 5 | |
| username: postgres | |
| password: | |
| production: | |
| adapter: postgresql | |
| encoding: unicode | |
| database: launchbay_production | |
| pool: 5 | |
| username: postgres | |
| password: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #config/environments/development.rb | |
| Launchbay::Application.configure do | |
| # Settings specified here will take precedence over those in config/application.rb. | |
| config.cache_classes = false | |
| config.eager_load = false | |
| config.consider_all_requests_local = true | |
| config.action_controller.perform_caching = false | |
| config.action_mailer.raise_delivery_errors = false | |
| config.active_support.deprecation = :log | |
| config.active_record.migration_error = :page_load | |
| config.assets.debug = true | |
| config.ember.variant = :development | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #app/assets/javascripts/models/epic.js.coffee | |
| App.Epic = DS.Model.extend | |
| name: DS.attr('string') | |
| body: DS.attr('string') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #app/models/epic.rb | |
| class Epic < ActiveRecord::Base | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #app/serializers/epic_serializer.rb | |
| class EpicSerializer < ActiveModel::Serializer | |
| attributes :id, :name, :body | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #app/assets/javascripts/routes/epics.js.coffee | |
| App.EpicsRoute = Ember.Route.extend | |
| model: -> | |
| @get('store').findAll 'epic' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #app/controllers/api/v1/epics_controller.rb | |
| class Api::V1::EpicsController < ApplicationController | |
| respond_to :json | |
| def index | |
| respond_with Epic.all | |
| end | |
| def show | |
| respond_with Epic.find(params[:id]) | |
| end | |
| private | |
| def epic_params | |
| params.require(:epic).permit(:name, :body) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| source 'https://rubygems.org' | |
| gem 'rails', '4.0.0' | |
| gem 'pg' | |
| gem 'sass-rails', '~> 4.0.0' | |
| gem 'uglifier', '>= 1.3.0' | |
| gem 'coffee-rails', '~> 4.0.0' | |
| gem 'jquery-rails' | |
| gem 'jbuilder', '~> 1.2' | |
| group :doc do | |
| # bundle exec rake doc:rails generates the API under doc/api. | |
| gem 'sdoc', require: false | |
| end | |
| # Use debugger | |
| # gem 'debugger', group: [:development, :test] | |
| gem 'ember-rails' | |
| #gem 'ember-source', '~> 1.0.0' | |
| gem 'emblem-rails' | |
| gem 'haml-rails' | |
| gem 'sass-rails', '~> 4.0.0' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #app/controllers/home_controller.rb | |
| class HomeController < ApplicationController | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -#app/views/home/index.html.haml | |
| %script{ type: 'text/x-handlebars' } | |
| {{ outlet }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #app/assets/javascripts/router.js.coffee | |
| App.Router.map ()-> | |
| @resource 'epics' | |
| @resource 'stories' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #config/routes.rb | |
| Launchbay::Application.routes.draw do | |
| root to: 'home#index' | |
| namespace :api do | |
| namespace :v1 do | |
| resources :epics, only: [:index, :show] | |
| resources :stories, only: :index | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #app/assets/javascripts/store.js.coffee | |
| App.ApplicationAdapter = DS.RESTAdapter.extend | |
| namespace: 'api/v1', | |
| configure: 'plurals', story: 'stories' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #app/assets/javascripts/routes/stories.js.coffee | |
| App.StoriesRoute = Ember.Route.extend | |
| model: -> | |
| @get('store').findAll 'story' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -# app/assets/javascripts/templates/stories.js.emblem | |
| h1 Story Listing | |
| = each story in controller | |
| h2= story.name | |
| | {{{story.body}}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #app/controllers/api/v1/stories_controller.rb | |
| class Api::V1::StoriesController < ApplicationController | |
| respond_to :json | |
| def index | |
| respond_with Story.all | |
| end | |
| private | |
| def story_params | |
| params.require(:story).permit(:name, :body) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #app/assets/javascripts/models/story.js.coffee | |
| App.Story = DS.Model.extend | |
| name: DS.attr('string') | |
| body: DS.attr('string') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #app/models/story.rb | |
| class Story < ActiveRecord::Base | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #app/serializers/story_serializer.rb | |
| class StorySerializer < ActiveModel::Serializer | |
| attributes :id, :name, :body | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Made your suggested changes, but still not working. I however am using sqlite3 in development. and the error that I am getting is
NoMethodError in Home#indexDo you have a demo deployed. I would actually like to see this thing in action.