小编sil*_*m99的帖子

来自Rack中间件的Alter Rails params哈希

我试图从自定义Rack中间件对象的Rails参数哈希添加一个值.我目前的方法是使用

class PortalResolver

 def initialize(app)
   @app = app
 end

  def call(env)
    begin
      url = "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}"
      request = Rack::Request.new(env)
      portal_id = DomainService.domain(url) # DomainService is returning the expected value
      request.params['portal_id'] = portal_id
      status, headers, response = @app.call(env)
      [status, headers, response]
    rescue PortalNotFoundError => e
      [403, {'Content-Type' => 'text/html'}, ['']]
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

我目前正在ActionDispatch :: ParamsParser之后添加中间件.这些参数不会出现在来自控制器的Rails params散列中,但会显示在request.params散列中(在上面定义的中间件对象中).任何想法?非常感谢.

ruby rack ruby-on-rails

11
推荐指数
1
解决办法
6132
查看次数

在Ember.js中创建新的mixin时如何扩展多个mixin

我之前发现在创建新的mixin时可以扩展mixin:

App.SomeNewMixin = Ember.Mixin.create(App.SomeOldMixin, {
  someMethod: function() { return true; }
});
Run Code Online (Sandbox Code Playgroud)

现在我试图使用两个现有的mixin,但似乎Mixin.create只支持2个参数.

App.SomeNewMixin = Ember.Mixin.create(App.SomeOldMixinOne, App.SomeOldMixinTwo, {
  someMethod: function() { // No access to methods defined in SomeOldMixinOne }
});
Run Code Online (Sandbox Code Playgroud)

这似乎是Ember Mixins的严重限制.Ember文档对Ember.Mixin几乎没有报道,所以我不确定如何继续.我尝试在SomeNewMixin的init函数中使用Ember.Mixin.apply,也无济于事.

App.SomeNewMixin = Ember.Mixin.create({
  init: function() {
    this._super();
    this.apply(App.SomeOldMixinOne);
    this.apply(App.SomeOldMixinTwo);
  }

  someMethod: function() { return true; }
});
Run Code Online (Sandbox Code Playgroud)

任何有关可能的解决方案的见解将不胜感激!

mixins ember.js

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

标签 统计

ember.js ×1

mixins ×1

rack ×1

ruby ×1

ruby-on-rails ×1