小编Ale*_*cia的帖子

将实例初始化程序与Ember 1.12.0和Ember CLI一起使用

将我的应用程序更新为Ember 1.12.0后,我注意到许多类似的警告:

lookup是在注册表上调用的.该initializerAPI不再接收一个容器,你应该使用一个instanceInitializer从容器中查找对象.有关详细信息,请参阅http://emberjs.com/guides/deprecations#toc_deprecate-access-to-instances-in-initializers.

这似乎是由container.lookup初始化程序使用引起的,这在旧版本的Ember中很好.

在关于Ember 1.12.0的博客文章中,似乎在基于全球的Ember应用程序中,创建初始化程序和实例初始化程序之间的区别在于

App.initializer({
    ...
});
Run Code Online (Sandbox Code Playgroud)

VS

App.instanceInitializer({
    ...
});
Run Code Online (Sandbox Code Playgroud)

但是,它似乎没有描述如何使用Ember CLI使用实例初始化程序.有谁知道如何使用它们?

编辑:原来所有东西的浏览器插件阻止了原始博客文章中我需要的信息.我会留下这个,以防它对任何人都有用,但在CLI中常规初始化器进入

app/initializers/__my__initializer.js
Run Code Online (Sandbox Code Playgroud)

实例初始化器定义为

app/instance-initializers/__my__initializer.js
Run Code Online (Sandbox Code Playgroud)

编辑2:如果有人因为遇到同样的问题而来到这里,Ember.js repo上的这个问题引用了这个问题,并包含了一个jsfiddle的链接,证明了这个问题.

ember.js ember-cli

17
推荐指数
1
解决办法
3152
查看次数

让nokogiri使用更新版本的libxml2

我一直试图将Nokogiri安装在我的电脑(Mountain Lion)上与rspec和capybara一起使用,但对于我的生活,我无法让它运行正常.

据我所知,问题在于nokogiri使用了错误版本的libxml2.到目前为止,我尝试使用Homebrew卸载并重新安装libxml2(确保它是最新版本),使用bundle卸载并重新安装nokogiri,并指定安装nokogiri gem时Homebrew安装的libxml2文件的确切路径.我最近的安装说明看起来像这样

sudo gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.0/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.0/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28
Run Code Online (Sandbox Code Playgroud)

所有这些位置都正确对应于安装工具的位置.但是,在运行时bundle exec rspec spec/requests/static_pages.rb,我仍然得到这个输出:

/Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri.rb:28:in `require': dlopen(/Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri/nokogiri.bundle, 9): Library not loaded: /usr/local/lib/libxml2.2.dylib (LoadError)
Referenced from: /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri/nokogiri.bundle
Reason: Incompatible library version: nokogiri.bundle requires version 12.0.0 or later, but libxml2.2.dylib provides version 10.0.0 - /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri/nokogiri.bundle
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri.rb:28:in `<top (required)>'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `require'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `each'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `block in require'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `each'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `require'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler.rb:132:in `require'
    from /Users/alex/Sites/harbingernews/config/application.rb:7:in …
Run Code Online (Sandbox Code Playgroud)

ruby rspec ruby-on-rails libxml2 nokogiri

6
推荐指数
3
解决办法
1万
查看次数

has_many的源反射错误:通过

我正在尝试创建一个系统,我的网站的用户可以在其中收藏页面.这些页面有两种类型,俱乐部或体育.所以,我有四个模型,相关联:

用户模型:

class User < ActiveRecord::Base
    ..
    has_many :favorites
    has_many :sports,    :through => :favorites
    has_many :clubs,     :through => :favorites
    ..
end
Run Code Online (Sandbox Code Playgroud)

收藏夹型号:

class Favorite < ActiveRecord::Base
    ..

    belongs_to :user
    belongs_to :favoritable, :polymorphic => true

end
Run Code Online (Sandbox Code Playgroud)

俱乐部型号:

class Club < ActiveRecord::Base
    ..

    has_many :favorites, :as => :favoritable
    has_many :users, :through => :favorites

    def to_param
      slug
    end
end
Run Code Online (Sandbox Code Playgroud)

运动模特:

class Sport < ActiveRecord::Base
    ..

    def to_param
        slug
    end

    ..

    has_many :favorites,   :as => :favoritable
    has_many :users,       :through => :favorites

    ..
end
Run Code Online (Sandbox Code Playgroud)

从本质上讲,用户可以通过收藏夹进行体育或俱乐部,而收藏,体育和俱乐部之间的关联是多态的. …

model ruby-on-rails polymorphic-associations model-associations rails-admin

4
推荐指数
1
解决办法
2505
查看次数