这是我在灰烬(现有的Rails应用程序)的第一次尝试,并有一些重要的资源在那里的interWeb,但考虑到我已经阅读所有这些,我仍然想要更多这是很好的检查笔记在这里。
我有一个新的模式:新闻链接 我建立了一个API,它:api/v1/newslinks.json
API工作原理:http://localhost:3000/api/v1/newslinks.json
数据
{"newslinks":[{"id":1,"title":"A Sample Post","navlink":"This will be a simple post record."}]}
代码
问题是,Ember似乎是lett通过其手中荷兰国际集团的路线滑(这是我做错了下面的代码,我敢肯定):
的application.js
//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require jquery-fileupload/basic
//= require jquery-fileupload/vendor/tmpl
//= require chosen-jquery
//= require bootstrap
//= require bootstrap-notify
//= require jquery.limit-1.2.source
//= require bootstrap-switch
//= require handlebars
//= require ember
//= require ember-data
//= require_self
//= require app
app.js
App = Ember.Application.create({
LOG_TRANSITIONS: true,
ready: function() {
console.log('App ready');
}
});
App.Router.map(function() {
this.resource('newslinks', { path: '/' });
});
App.IndexRoute = Ember.Route.extend({
redirect: function() {
this.transitionTo('newslinks');
}
});
App.NewslinksRoute = Ember.Route.extend({
model: function() {
return App.Newslink.find();
}
});
DS.RESTAdapter.reopen({
namespace: 'api/v1'
});
App.Store = DS.Store.extend({
revision: 13
});
App.Newslink = DS.Model.extend({
name: DS.attr('string')
});
Application.handlebars
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Ember - Latest" />
<meta charset=utf-8 />
<title>Ember Latest</title>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0-rc1/css/bootstrap.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0-rc1/js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://builds.emberjs.com/handlebars-1.0.0.js"></script>
<script src="http://builds.emberjs.com/ember-latest.js"></script>
<script src="http://builds.emberjs.com/ember-data-latest.js"></script>
</head>
<body>
<script type="text/x-handlebars">
<h2>Here I am</h2>
</script>
</body>
</html>
的routes.rb
App::Application.routes.draw do
namespace :api do
namespace :v1 do
resources :newslinks
end
end
我甚至试图返回数据还没有。只是想看到路由连接,但我得到一个路由错误。我如何确保Ember看到URL“/ newslinks”?
让我知道你是否有任何建议。谢谢!
随机无关观察
Ember.js好像读博尔赫斯的迷宫,好东西很多,而且我可以告诉它会得到后续的读数要好得多,直到一切都只是非常有意义。
可能的重复[使用“ember-rails”将现有Rails应用程序从Rails迁移到Ember)(http://stackoverflow.com/questions/18091588/migrate-routes-from-rails-to-ember-with -existing-rails-application-using-ember) –