我正在尝试使用emberjs来渲染我的内容,以便内容不会重新加载
我遇到的问题是似乎没有任何渲染
的application.js
#= require jquery
#= require jquery_ujs
#= require jquery.ui.all
#= require date
#= require misc
#= require foundation
#= require handlebars
#= require ember
#= require ember-data
#= require_self
App = Ember.Application.create(
LOG_TRANSITIONS: true
ready: ->
console.log "App ready"
return
)
App.Router.map ->
@resource "admin/pages",
path: "/admin/pages"
return
App.IndexRoute = Ember.Route.extend(redirect: ->
@transitionTo "admin/pages"
return
)
App.NewslinksRoute = Ember.Route.extend(model: ->
App.Page.find()
)
DS.RESTAdapter.reopen namespace: "admin/pages"
App.Store = DS.Store.extend(revision: 13)
App.Page = DS.Model.extend(name: DS.attr("string"))
# for more details see: http://emberjs.com/guides/application/
#window.Grokphoto = Ember.Application.create()
$ ->
$(document).foundation()
return
的routes.rb
match 'admin' => 'admin/pages#index'
namespace :admin do
resources :events, :only => :index
resource :photographer, :only => [:edit, :update]
resources :pages
resources :posts
resources :galleries
resources :private_galleries do
get :invite, :on => :member
put :send_invite, :on => :member
end
resources :photos, :only => [:edit, :update, :destroy] do
put 'sort', :on => :collection
end
end
然后在/assets/javascripts/templates/admin/page/index.hbs我有以下
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Ember - Latest" />
<meta charset=utf-8 />
<title>Ember</title>
<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>Ember Works</h2>
</script>
</body>
</html>
如果我可以让它呈现出来我应该能够完成其余的工作
答案 0 :(得分:4)
rails new app
cd app
# remove gem 'coffee-rails' from Gemfile if not needed
echo "gem 'ember-rails'" >> Gemfile
echo "gem 'ember-source', '1.3.0'" >> Gemfile
bundle
rails g ember:bootstrap
rails g controller home index
(Remove the lines in the view file)
# config/routes.rb
root 'home#index'
# config/environments/development.rb
echo "Hello world" >> app/assets/javascripts/templates/index.hbs
http://localhost:3000
Voila :)
以下是Rails中emberjs的工作原理。 emberjs
只是 javascript ,甚至可以进行路由(更改/#/posts
等网址。)
在Rails中,当您向/admin
发出请求时,会在您的情况下映射到'admin/pages#index'
。
views/layouts/application.html.erb
admin/pages#index
视图。当你有emberjs时也会发生同样的事情,没有什么特别的,没有任何改变这个顺序,除了你不需要从你的admin/pages#index
视图文件中渲染任何东西,它可以是空白的。
但是您需要layouts/application.html.erb
,因为您拥有所有的javascript
<%= javascript_include_tag "application" %>
现在是/admin
然后创建一个文件app/assets/javascripts/templates/index.hbs
它应该工作!我建议你尝试创建新的rails项目以获得一些想法并开始迁移。