小编Bil*_*ill的帖子

after_create:foo vs after_commit:bar,:on =>:create

之间有什么区别:

after_create :after_createafter_commit :after_commit_on_create, :on => :create

这些可以互换使用吗?

ruby-on-rails

47
推荐指数
2
解决办法
2万
查看次数

Rails 4 pgsql add_index,类型为GIN或GiST

在Rails中可以这样做:

add_index :table, :column_name, :using => 'btree'

是否可以在带有PGSQL的Rails 4中添加GINGiST索引如下:

add_index :students, :name, :using => 'gin'

或者我是否使用手动执行语句?这背后的概念是我想保留schema.rb而不是使用structure.sql

postgresql ruby-on-rails ruby-on-rails-4

32
推荐指数
2
解决办法
1万
查看次数

使用Angular.js + UI路由器进行Karma测试

我想知道如何使用Angular.js + UI路由器进行Karma测试?

我定义了以下状态:哪个有两个解析器来获取一些数据并为控制器准备数据.(来自Ember背景,这很有道理.)

$stateProvider
  .state('users', {
    resolve: {
      getData: function (User) {
        return User.query().$promise
      },
      stateModels: function (getData) {
        var models = {}
        models.users = getData
        return models
      }
    },
    url: '/',
    templateUrl: '/views/users/index.html',
    controller: 'UsersIndexCtrl'
  })
Run Code Online (Sandbox Code Playgroud)

我们的UserIndexCtrl看起来像:(它接受已解析的stateModels并将其分配给$ scope,因此视图可以使用它)

app.controller('UsersIndexCtrl', [
  '$scope', '$state', 'stateModels',
  function ($scope, $state, stateModels) {

    $scope.users = stateModels.users

  }])
Run Code Online (Sandbox Code Playgroud)

这在浏览器中运行良好,我看到了正确的结果.但是,当涉及到测试时,它给了我奇怪的错误.

以下是Karma单元测试的示例:

describe('controllers', function () {

  var $httpBackend
    , $rootScope
    , $scope
    , $state
    , $httpBackend
    , $controller

  beforeEach(module('app'))

  beforeEach(inject(function ($injector) { …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs karma-runner angular-ui-router

14
推荐指数
1
解决办法
8236
查看次数

将 GCP PostgreSQL 表同步到 GCP BigQuery

我们目前正在使用 Stitchdata 定期将数据从 PostgreSQL 实例同步到 BigQuery 实例。该数据用于构建报告。Stitchdata 允许使用一些复选框和选项构建管道,而无需编码。

我想知道 Google Cloud Platform 是否提供了允许 PostgreSQL 数据库(由 GCP 托管)同步到 BigQuery 表的解决方案。这是出于数据主权和用户数据隐私问题的目的。

我们不想使用,federated queries因为我们只想将某些列从 PostgreSQL 导入到 BigQuery。

我看过:

  • Datastream + Data Fusion(Datastream 尚不支持 Postgres)
  • BigQuery 数据传输 + Fivetran Postgres 连接器(这将导致数据传输到第三方处理器。)
  • 数据融合(PostgreSQL 不支持复制)

我很好奇我是否遗漏了 Google Cloud Platform 提供的将 PostgreSQL 数据库中的数据同步到 BgigQuery 的任何明显明显的内容。

干杯

postgresql google-bigquery google-cloud-platform

9
推荐指数
1
解决办法
1726
查看次数

Rails:在视图上下文之外使用JBuilder视图

我目前切换ActiveModelSeralizerJBuilder渲染jsons.我想知道,ActiveModelSeralizer我可以这样做:

text_content = UserSeralizer.new(user, :root => false)
Run Code Online (Sandbox Code Playgroud)

并在变量中接收json字符串text_content.既然我正在转离ActiveModelSeralizer,那么无论如何都要使用JBuilder进行上述操作吗?

我有一个部分内部的视图app/view/api/v1/users/_user.json.jbuilder是否仍然将该部分变为变量?

谢谢

json ruby-on-rails

8
推荐指数
3
解决办法
2719
查看次数

为什么HTTP/2的浏览器实现需要TLS?

为什么大多数现代浏览器都需要HTTPS的TLS?

这背后有技术原因吗?或者只是为了让网络更安全?

http://caniuse.com/#feat=http2

firefox google-chrome http http2

8
推荐指数
1
解决办法
1440
查看次数

gem install rails不安装rails

当我尝试安装rails时:

root@li44-48:/# gem install rails
Successfully installed rails-3.2.1
1 gem installed
Installing ri documentation for rails-3.2.1...
Installing RDoc documentation for rails-3.2.1...
Run Code Online (Sandbox Code Playgroud)

但当我这样做时:

root@li44-48:/# rails
-bash: rails: command not found
Run Code Online (Sandbox Code Playgroud)

我查了一下gem env它显示:

RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.15
  - RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [i686-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: /usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-linux
  - GEM PATHS:
     - /usr/lib/ruby/gems/1.9.1
     - /root/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails

7
推荐指数
2
解决办法
9729
查看次数

Rails 5测试全局设置和拆卸

我正在使用针对Rails 5 beta的开箱即用的香草测试套件。我想知道是否有人想出了如何运行全局设置并拆除的方法。

我要在开始任何测试之前启动内存中的Elasticsearch集群并在测试完成后停止集群,这是我需要这样做的原因。

Rspec不是一个选择。

ruby ruby-on-rails

7
推荐指数
2
解决办法
1616
查看次数

使用ActiveRecordStore + Sticky Sessions的RoR Cookies

我有一个RoR Web应用程序(w/mysql),它在几个相同的服务器上进行负载平衡.该应用程序需要cookie和会话才能运行.

目前,客户端始终路由到负载均衡器后面的同一服务器,如果服务器被关闭,客户端将被路由到不同的服务器,并且它们的会话将结束.

当前架构的负载均衡器仅在同一数据中心内负载均衡机器.我想使用多个数据中心在地理上使用DNS循环进行负载平衡,并提供额外的冗余.

如果我要在我的RoR应用程序中打开ActiveRecordStore进行会话存储,这应该解决上面的问题,客户端可以路由到每个服务器,并且它们的会话将完好无损.它是否正确?

使用ActiveRecordStore会话有严重的后果吗?

activerecord ruby-on-rails-3

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

Rails 4 Has_many:通过join与join联系

我正在尝试将rails 3.0应用程序升级到rails 4.0.我注意到的一个行为是模型之间的关系停止工作.

假设我们有以下型号:

class Student < ActiveRecord::Base
  has_many :teacher_students
  has_many :teachers, :through => :teacher_students, :select => 'teacher_students.met_with_parent, teachers.*'

  # The Rails 4 syntax
  has_many :teachers, -> { select('teacher_students.met_with_parent, teachers.*') }, :through => :teacher_students

end

class Teacher < ActiveRecord::Base
  has_many :teacher_students
  has_many :students, :through => :teacher_students, :select => 'teacher_students.met_with_parent, students.*'
end

class TeacherStudent < ActiveRecord::Base
  belongs_to :teacher
  belongs_to :student
  # Boolean column called 'met_with_parent'
end
Run Code Online (Sandbox Code Playgroud)

现在我们可以做到:

teacher = Teacher.first
students = teacher.students
students.each do |student|
  student.met_with_parent     # Accessing this column …
Run Code Online (Sandbox Code Playgroud)

ruby activerecord ruby-on-rails ruby-on-rails-3 ruby-on-rails-4

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

Jasmine Testing获得完整描述/它的名称

我想知道,是否有可能获得测试的完整嵌套描述路径?

鉴于:

describe('Smoke Testing - Ensuring all pages are rendering correctly and free of JS errors', function () {
  describe('app', function () {
    describe('app.home', function () {
      it('should render this page correctly', function (done) {
        //name here should be: Smoke Testing - Ensuring all pages are rendering correctly and free of JS errors app app.home should render this page correctly
        done()
      })
    })

    describe('app.dashboard', function () {
      describe('app.dashboard.foobar', function () {
        it('should render this page correctly', function (done) {
        //name …
Run Code Online (Sandbox Code Playgroud)

jasmine protractor

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

我可以使用"gsub!"作为变量传入块吗?

我可以:

'string'.gsub!(/something/) do
  ... complex replacement here ...
  'final result'
end
Run Code Online (Sandbox Code Playgroud)

我想知道是否可以将do ... end块分配给变量并gsub!作为参数传入,以便我可以执行以下操作:

my_block_replacement_logic = {
  ... complex replacement here ...
  'final result'
}
Run Code Online (Sandbox Code Playgroud)

然后拨打gsub:

this_string.gsub!(/something/, my_block_replacement_logic)
that_string.gsub!(/something/, my_block_replacement_logic)
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails

2
推荐指数
1
解决办法
370
查看次数