0

currently I'm having a little trouble rendering my JSON posts in ember, the structure of my app has my config.ru file at the front, another public folder with all the ember content inside. The app works, it just won't render the posts, it worked with sinatra + ember but since I racked grape I've been having trouble. Any help will be greatly appreciated thanks.

Config.ru:

require 'sinatra'
require 'JSON'
require 'grape'
require 'sinatra/base'

$posts = {}
$posts[123] = {:title => "Rails is Omakase",
:id => 123,
:_id => 987,
:author => "d2h",
:publishedAt => Date.new(),
:intro => "There are lots of  la carte software environments in this world. Places         where in order to eat, you must first carefully look over the menu of options to order   exactly what you want.",
:extended => "I want this for my ORM, I want that for my template language, and let's   finish it off with this routing library. Of course, you're going to have to know what you   want, and you'll rarely have your horizon expanded if you always order the same thing, but   there it is. It's a very popular way of consuming software.\n\nRails is not that. Rails is     omakase."
  }

put '*/:id' do
 p "entering PUT /*/:id", params
 raw = request.env["rack.input"].read  ## this is the JSON data as a string
 p "raw:", raw
 $posts[params[:id].to_i] = JSON.parse(raw)['post'].merge({:id => params[:id].to_i})
 p "\n\n+++++  $posts:", $posts
 {:id => params[:i]}.to_json
end


class API < Grape::API
 default_format :json
 get '/posts' do
  mount API::posts => '/posts'
  data = {:posts => $posts.values}.to_json 
  return data 
end
end

 class Web < Sinatra::Base
  get '/posts' do
  p "entering GET"
  data = {:posts => $posts.values}.to_json
  p "\n*** data:", data
 data
end

get '/' do
 File.read(File.join('public', 'index.html'))
end
end

use Rack::Session::Cookie
run Rack::Cascade.new [API, Web]

app.js:

  App = Ember.Application.create({});

  App.Store = DS.Store.extend({
   revision: 12,
   adapter: DS.RESTAdapter.extend({
   url: 'http://localhost:4567'
  })
 });

App.Router.map(function() {
  this.resource('about');
  this.resource('posts', function() {
  this.resource('post', { path: ':post_id' });
 });
});

 App.PostsRoute = Ember.Route.extend({
  model: function() {
  return App.Post.find();
 }
  });

App.PostController = Ember.ObjectController.extend({
 isEditing: false,

edit: function() {
 this.set('isEditing', true);
},

doneEditing: function() {
  this.set('isEditing', false);
  this.get('store').commit();
 }
});

var attr = DS.attr;

App.Post = DS.Model.extend({
title: attr('string'),
author: attr('string'),
intro: attr('string'),
extended: attr('string'),
publishedAt: attr('date')
});

var showdown = new Showdown.converter();

Ember.Handlebars.registerBoundHelper('markdown', function(input) {
 return new Handlebars.SafeString(showdown.makeHtml(input));
});

Ember.Handlebars.registerBoundHelper('date', function(date) {
 return moment(date).fromNow();
});

Github repo : https://github.com/FatOblivion/blogger

Neal
  • 573
  • 3
  • 16

0 Answers0