问题描述
我正在尝试为我正在开发的Rails 3.1应用程序编写一个萌芽核心前端.我看过萌芽指南,但是我有兴趣看到一些实际示例,将如何将萌芽与Rails 3(.1)一起使用.
I am trying to write a sproutcore frontend for a rails 3.1 application I am making. I have had a look at the sproutcore guides, but I am interested in seeing real examples how to use sproutcore together with rails 3(.1).
我找到了两个示例,但每个示例都完全不同:
I have found two examples, but each is totally different:
- 使用 todo-app drogus/bulk_api> bulk_api :一种有趣的方法,使用特定的REST样式来最小化流量.但是它建议将萌芽应用程序放置在
app/sproutcore
中,但我仍然不清楚它实际上是如何完全挂接的. - Travis-ci ,这似乎是一个非常干净的示例,使用rails 3.1即可使用发芽核心.对我来说还不是很清楚,但是所有的萌芽js都干净地存储在
app/assets/javascript/apps
内,据我所知,application.html
只是加载js并提供将所有内容加载到其中的框架.
- A todo-app created using bulk_api: an interesting approach using a specific REST-style to minimise the traffic. But it proposes to place the sproutcore app in
app/sproutcore
, and is still a bit unclear to me how that actually hooks in completely. - Travis-ci which seems to be a very clean example, rails 3.1, to use sproutcore. It is not yet completely clear to me, but all sproutcore js is cleanly stored inside
app/assets/javascript/apps
and as far as i can tell, theapplication.html
just loads the js and provides the frame where everything is loaded into.
您还知道其他示例吗?您如何在Rails应用程序中使用萌芽核心?
Do you know any other examples? How do you use sproutcore in your rails app?
推荐答案
您描述的方法与将boundary.js集成到Rails应用程序中的方式相同,并且似乎工作得很好
The method you describe is the same way that you integrate backbone.js into a rails app, and it seems to work very well
https://github.com/codebrew/backbone-rails
此将主干存储在
app/assets/javascripts/backbone/
app/assets/javascripts/backbone/app/models
app/assets/javascripts/backbone/app/controllers
app/assets/javascripts/backbone/
app/assets/javascripts/backbone/app/models
app/assets/javascripts/backbone/app/controllers
然后在视图中有一个脚本标签仅用于初始化骨干
And then there is a script tag in the view that just initializes backbone
<script type="text/javascript">
$(function() {
// Blog is the app name
window.router = new Blog.Routers.PostsRouter({posts: <%= @posts.to_json.html_safe -%>});
Backbone.history.start();
});
</script>
我认为类似的发芽过程很有意义
I imagine a similar process for sproutcore would make sense
这篇关于结合了rails 3和萌芽核心的良好示例应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!