在ember-data中find,findAll和findQuery有什么区别?
我正在从rails 3.0.7升级到3.1,并且无法通过测试.当我尝试在工厂中使用存根活动资源对象时,会发生此问题.
#employee.rb
class Employee < ActiveResource::Base; end
#task.rb
class Task < ActiveRecord::Base
belongs_to :employee
end
#factories.rb
Factory.define :employee do |e|
e.name "name"
end
Factory.define :task do |t|
t.employee { Factory.stub(:employee) }
end
Run Code Online (Sandbox Code Playgroud)
在控制台和规范存根中,员工工作.在新任务中引用存根的员工对象会产生以下错误.
Factory.create( :task, :employee => Factory.stub(:employee) )
NoMethodError:
undefined method `[]' for #<Employee:0x007fc06b1c7798>
Run Code Online (Sandbox Code Playgroud)
编辑
这不是工厂女孩的问题.如果我在控制台中执行以下操作,则会出现相同的错误.
Task.new( :employee => Employee.first )
Run Code Online (Sandbox Code Playgroud)
它必须与belongs_to如何映射id列有关.
我将capistrano配置为跨三个物理服务器进行部署.我想配置重启任务以顺序转到每个服务器并重新启动应用程序,而不是一次性转到所有服务器的默认方式.
这是当前的部署任务:
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && bundle exec unicorn_rails -c #{current_path}/config/unicorn.rb -E #{rails_env} -D"
end
task :stop, :roles => :app, :except => { :no_release => true } do
run "kill `cat #{current_path}/tmp/pids/unicorn.pid`"
end
task :restart, :roles => :app, :except => { :no_release => true } do
stop
sleep(10)
start
end
end
Run Code Online (Sandbox Code Playgroud)
我在想这样的事情:
#this does not work
task :sequential_restart do
find_servers(:roles => :app).each
restart
end …Run Code Online (Sandbox Code Playgroud) 我在使用query-params-new功能时遇到问题.
我的ember版本是1.4.0-beta.2.
Ember.js通过ember-rails和ember-source宝石加载到我的rails应用程序中.
在初始化Ember应用程序之前,我打开了这样的功能.
Ember.FEATURES["query-params-new"] = true
Run Code Online (Sandbox Code Playgroud)
执行此操作后,导航到任何路径时出现以下错误.
Error while loading route: TypeError: Object [object Object] has no method 'paramsFor' at Ember.Route.Ember.Object.extend.deserialize
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?我是否需要在每条路线上定义一个paramsFor方法?
我在使用ember-cli 0.0.28时遇到了麻烦.我的所有初始化程序都无法加载.我收到以下错误.
未捕获的ReferenceError:未定义模块
为每个初始值设定项创建的每个jshit.js文件都会引发错误.
例:
define("fp-mobile/initializers/authentication.jshint",
[],
function() {
"use strict";
### This is the line that is blowing up.
module('JSHint - fp-mobile/initializers');
### Uncaught ReferenceError: module is not defined
test('fp-mobile/initializers/authentication.js should pass jshint', function() {
ok(true, 'fp-mobile/initializers/authentication.js should pass jshint.');
});
});//# sourceURL=fp-mobile/initializers/authentication.jshint.js
Run Code Online (Sandbox Code Playgroud)
这是在从ember-cli 27升级到ember-cli 0.0.28-master-cbd7c7c264之后开始的.
任何人都知道可能导致这种情况的原因.我应该打开一个bug吗?
我刚刚升级到最新的canary版本的ember,并注意到我的初始化程序将currentUser控制器注入所有控制器不再有效.
这是代码.
Ember.Application.initializer({
name: "fetchUsers",
after: "store",
initialize: function(container, application) {
var store, controller;
application.deferReadiness();
store = container.lookup('store:main');
controller = container.lookup('controller:currentUser');
return store.find('user').then( function(users) {
var currentUser;
currentUser = users.findBy('isCurrent', true);
controller.set('content', currentUser);
application.inject('controller', 'currentUser', 'controller:currentUser');
application.advanceReadiness();
});
}
});
Run Code Online (Sandbox Code Playgroud)
这在发布和beta分支中运行良好但在金丝雀中我得到以下错误.
Error: Cannot inject a `controller:current-user` on other controller(s). Register the `controller:current-user` as a different type and perform the typeInjection.
Run Code Online (Sandbox Code Playgroud)
我该怎么办呢?我想currentUser是一个ObjectController,这可能吗?
鉴于以下coffeescript.
App.Whatever = Em.ArrayController.extend
clean: Em.computed ->
@get('content').filterBy('clean', true)
.property 'content'
Run Code Online (Sandbox Code Playgroud)
Coffeescript <1.7会正确输出:
App.Whatever = Em.ArrayController.extend({
clean: Ember.computed(function() {
return this.get('content').filterBy('clean', true);
}).property('content')
});
Run Code Online (Sandbox Code Playgroud)
现在Coffeescript 1.7输出:
App.Whatever = Em.ArrayController.extend({
clean: Ember.computed(function() {
return this.get('content').filterBy('clean', true);
})
}).property('content');
Run Code Online (Sandbox Code Playgroud)
这似乎是一个外卖.我错过了什么或者我是否必须重写所有计算属性?
从Ember.CollectionView有一个简单的方法来渲染所有childView元素后调用一个函数?
像所有孩子的didInsertElement一样.
这就是我现在正在做的事情.有没有更好的办法?
App.CollectionView = Ember.CollectionView.extend
didInsertChildElements: ( ->
if @get('childViews').everyProperty('state', 'inDOM')
@dosomething()
).observes('childViews')
itemViewClass: Ember.View.extend()
Run Code Online (Sandbox Code Playgroud)
编辑这里是我想要做的更好的例子.
对于每个ChildView,我使用didInsertElement设置位置,然后从父级我想使用父级didInsertElement回调滚动到指定的子级.问题是在子进程之前调用父进程的didInsertElement回调.
App.CollectionView = Ember.CollectionView.extend
dateBinding: 'controller.date'
didInsertElement: ->
#@scrollTo @get('date')#old way
Ember.run.scheduleOnce('afterRender', @, 'scrollToDate')
scrollToDate: ->
@scrollTo @get('date')
scrollTo: (date) ->
day = @get('childViews').findProperty('date', date)
pos = day.get('position')
#console.log pos
@$().scrollTop(pos)
itemViewClass: Ember.View.extend
templateName: 'home/day'
dateBinding: 'content.date'
position: null
didInsertElement: ->
@set 'position', @$().offset().top
#console.log @get('position')
Run Code Online (Sandbox Code Playgroud)
编辑
调度afterRender回调有效!Ember.run.scheduleOnce('afterRender',@,'scrollToDate')
当我更改模型的属性时,我收到以下错误.
Uncaught Error: <DS.StateManager:ember466> could not respond to event setProperty in state rootState.loading.
Run Code Online (Sandbox Code Playgroud)
这是代码.http://jsfiddle.net/arenoir/JejwD/ http://jsfiddle.net/arenoir/JejwD/show
从控制器或视图调用路由的正确方法是什么.例如,我有一个包含许多行的表.每一行View都有一个应该调用路由器的click方法.它不起作用我无法从控制器或视图导航应用程序.
这是一个例子:http://jsfiddle.net/arenoir/Cs938/
App.TableView = Ember.CollectionView.extend({
tagName: 'table',
contentBinding: 'controller.rows',
itemViewClass: Ember.View.extend({
tagName: 'tr',
template: Ember.Handlebars.compile("<td>{{view.content.name}}"),
click: function(){
var router, tab;
router = this.get('controller.target.router');
tab = this.get('content.id');
router.goTab(tab);
}
})
});
Run Code Online (Sandbox Code Playgroud)
以下帖子很有帮助.EmberJS:如何从控制器的动作转换到路由器.
我无法使用ember-data rev12实现我所理解的多态关系.
我有以下型号:
App.Project = DS.Model.extend
lists: DS.hasMany('App.List', { polymorphic: true })
App.Proposal = DS.Model.extend
lists: DS.hasMany('App.List', { polymorphic: true })
App.Employee = DS.Model.extend
lists: DS.hasMany('App.List', { polymorphic: true })
App.List = DS.Model.extend
name: DS.attr('string')
#project: DS.belongsTo('App.Project', { polymorphic: true })
Run Code Online (Sandbox Code Playgroud)
我试图从项目路由器创建一个新的列表,如此.
App.ProjectRoute = Ember.Route.extend
events:
newList: (project) ->
lists = project.get('lists')
list = App.List.createRecord(name: 'list1')
lists.pushObject(list)
@store.commit()
Run Code Online (Sandbox Code Playgroud)
但是对服务器的请求是错误地设置了多态键.
我期待有效载荷看起来像:
{ list: { name: list1, listable_type: project, listable_id: 100 } }
Run Code Online (Sandbox Code Playgroud)
但得到了:
{ list: { name: list1, project_type: project, project_id: …Run Code Online (Sandbox Code Playgroud)