現在、JSON 投稿を ember でレンダリングするのに少し問題があります。アプリの構造には、config.ru ファイルが前面にあり、別のパブリック フォルダーにすべての ember コンテンツが含まれています。アプリは機能しますが、投稿がレンダリングされないだけで、sinatra + ember で機能しましたが、ブドウを集めて以来、問題が発生しています。どんな助けでも大歓迎ですありがとう。
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 リポジトリ: https://github.com/FatOblivion/blogger