小编Mat*_*ski的帖子

使用sql变量更新PostgreSQL hstore字段

我有files一个有hstore列的表details.在我的sql语句中,我向其插入数据:

  UPDATE files SET details =  'new_users=>new_users_count'::hstore where id = v_file_id;
Run Code Online (Sandbox Code Playgroud)

但我想更新这个hstore字段不是用字符串,而是用我的sql语句中提供的变量.我怎样才能做到这一点?

sql postgresql hstore

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

使用 rspec 测试 aasm 状态转换

我正在使用 aasm gem 来处理我的项目中的状态转换。我有一个简单的模型,如下所示:

class TransferPostingBid < ActiveRecord::Base
  include AASM

  aasm :status do
    state :offered, initial: true
    state :wait_for_pap_confirmation
    state :confirmed_by_pap
    state :retracted_by_pap

    event :pap_choosed do
      transitions from: :offered, to: :wait_for_pap_confirmation
    end

    event :confirmed_by_pap do
      transitions from: :wait_for_pap_confirmation, to: :confirmed_by_pap
    end

    event :retracted_by_pap do
      transitions from: :wait_for_pap_confirmation, to: :retracted_by_pap
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用内置 rspec 匹配器的 aasm 测试转换:

require 'rails_helper'

describe TransferPostingBid, type: :model do
  describe 'state transitions' do
    let(:transfer_posting_bid) { TransferPostingBid.new }

    it 'has default state' do
      expect(transfer_posting_bid).to transition_from(:offered).to(:wait_for_pap_confirmation).on_event(:pap_choosed)
    end …
Run Code Online (Sandbox Code Playgroud)

ruby rspec ruby-on-rails state-machine aasm

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

覆盖Rails路由

在我的应用程序中,我有以下路线:

  namespace :partners do
    resources :cars
  end
Run Code Online (Sandbox Code Playgroud)

我的汽车索引是以下路线:

'localhost:3000/partners/cars/'

但我希望有这样的道路:

'localhost:3000/partners/all_cars/'

我怎样才能做到这一点?

routes ruby-on-rails ruby-on-rails-3.2 ruby-on-rails-4

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

检查文本是否具有等于@的第一个字符的正则表达式

我正在尝试编写一个正则表达式来检查文本的第一个字符是否等于@.例如:

  • @test - 这应该匹配

  • test @ test - 这应该不匹配

    我写了这样的东西:/(@[\w-]+)/i但是这个正则表达式也是第二个例子匹配,但它不应该......

ruby regex

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

无法在Linux Mint中安装curb gem

我有安装路边的问题.当我输入我的控制台时:

 sudo gem install curb
Run Code Online (Sandbox Code Playgroud)

它返回以下错误:

Fetching: curb-0.8.6.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing curb:
    ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
checking for curl-config... no
checking for main() in -lcurl... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib …
Run Code Online (Sandbox Code Playgroud)

ruby linux ruby-on-rails curb

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

未定义函数 put_req_header/3

我在 Phoenix 应用程序中有以下模块。此代码基本上是共享规范示例。它看起来像这样:

defmodule TattooBackend.CurrentPasswordRequiredTest do
  @moduledoc """
  This module defines tests that are testing api current password requirement.
  """
  import Phoenix.ConnTest

  alias TattooBackend.Web.Router

  defmacro test_current_password_required_for(method, path_name, action) do
    quote do
      test "without current password", %{conn: conn} do
        method    = unquote(method)
        path_name = unquote(path_name)
        action    = unquote(action)
        account = insert(:account)

        assert make_unauthenticated_request(conn, @endpoint, method, path_name, action, account) == %{
          "error" => "B??dne has?o."
        }
      end
    end
  end

  def make_unauthenticated_request(conn, endpoint, method, path_name, action, account) do
    path = apply(Router.Helpers, path_name, [conn, …
Run Code Online (Sandbox Code Playgroud)

elixir phoenix-framework

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

验证:条款,接受:真实不显示错误

在我的模型中,我有以下验证器:

validates :terms, acceptance: true, on: :create, allow_nil: false
attr_accessor :terms
Run Code Online (Sandbox Code Playgroud)

在我的形式我有:

= simple_form_for @reservation do |f|
  = f.error_notification
  = f.input :terms, as: :boolean 
Run Code Online (Sandbox Code Playgroud)

问题是,当用户不接受不显示任何错误的条款时,为什么?

ruby ruby-on-rails simple-form

0
推荐指数
2
解决办法
1345
查看次数

Rails,通过相关记录查找.

在我的应用程序中,我有两个模型:

class Address < ActiveRecord::Base
  belongs_to :location
end

class Location < ActiveRecord::Base
  #it has field city:string
  has_one :address
end
Run Code Online (Sandbox Code Playgroud)

现在我想找到所有解决城市字段的地点都有价值:"测试".我怎样才能做到这一点?提前致谢.

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

-1
推荐指数
1
解决办法
72
查看次数

Backbone ReferenceError

我有Backbone视图,如下所示:

App.Views.HistoricalDataSelector = Backbone.View.extend({
  initialize: function (options) {
    this.template = JST['backbone/templates/historical_data_selector'];
    this.collection = options.collection;
    this.model = options.model;
    this.render();
  },

  myCollection: function() {
    return this.collection.byReportType(this.model.get('report_type')).byReportOrganizationType(this.model.get('report_organization_type'))
  },

  render: function () {
    this.$el.html(this.template({
      collection: myCollection,
      model: this.model
    }));
  }
});
Run Code Online (Sandbox Code Playgroud)

当我尝试渲染它Backbone返回以下错误:

ReferenceError: myCollection is not defined
Run Code Online (Sandbox Code Playgroud)

但是当我将渲染方法更改为:

  render: function () {
    this.$el.html(this.template({
      collection: this.collection.byReportType(this.model.get('report_type')).byReportOrganizationType(this.model.get('report_organization_type')),
      model: this.model
    }));
  }
Run Code Online (Sandbox Code Playgroud)

为什么他找不到这个myCollection方法?

backbone.js

-1
推荐指数
1
解决办法
65
查看次数