Ruby on rails 混合主干.js路由器和rails控制器
我目前正试图将backbone.js移植到我的rails应用程序中。首先,我想将它构建到rails应用程序的特定部分at/applications。说到这里,我有一个rails资源“resources:applications”,它给了我localhost:3000/applications。现在,当我为/应用程序实例化主干时,我得到了rails资源中主干路由的锚定标记。IE localhost:3000/applications/#applications/5 考虑到我只会在rails应用程序的特定部分使用主干,因此不会使其成为单页应用程序,这是正确的方法吗?URL似乎有点多余 正确的答案可能是我需要取消主干路由器?如果是这样,那么在尝试查找集合/模型时如何将:id传递给主干应用程序 我使用主干网的目的是帮助组织rails应用程序的一个特定部分,该部分将使用大量javascript 我应该提到,我可以将路由器更改为:Ruby on rails 混合主干.js路由器和rails控制器,ruby-on-rails,backbone.js,ruby-on-rails-3.2,Ruby On Rails,Backbone.js,Ruby On Rails 3.2,我目前正试图将backbone.js移植到我的rails应用程序中。首先,我想将它构建到rails应用程序的特定部分at/applications。说到这里,我有一个rails资源“resources:applications”,它给了我localhost:3000/applications。现在,当我为/应用程序实例化主干时,我得到了rails资源中主干路由的锚定标记。IE localhost:3000/applications/#applications/5 考虑到我只会在rails应用程序
routes:
'': 'index'
':id': 'show'
这将为我提供localhost:3000/applications/#/1的url-但是我认为这将使我陷入困境,不允许我在其他rails资源上使用主干。如果调用带有主干的localhost:3000/dashboard,则会执行错误的backbone.js功能
另一个想法是对每个rails资源调用主干路由器。我可以使用前面提到的routes代码,因为路由器只会为rails资源调用。我最终找到了答案。我转而使用主干rails,并按照他们的教程启动并运行了一个示例应用程序。解决方案来自rails html.erb,只加载rails资源所需的特定路由器
routes:
"new" : "newPost"
"index" : "index"
":id/edit" : "edit"
":id" : "show"
".*" : "index"
然后在a posts.html.erb中,我可以放置以下内容
<div id="posts"></div>
<script type="text/javascript">
$(function() {
// Blog is the app name
window.router = new Testing.Routers.PostsRouter({posts: <%= @posts.to_json.html_safe -%>});
Backbone.history.start();
});
</script>
$(函数(){
//Blog是应用程序名
window.router=newtesting.Routers.postsruter({posts:});
Backbone.history.start();
});
如果我的答案没有意义,我建议阅读前面提到的github链接教程