我有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语句中提供的变量.我怎样才能做到这一点?
我正在使用 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) 在我的应用程序中,我有以下路线:
namespace :partners do
resources :cars
end
Run Code Online (Sandbox Code Playgroud)
我的汽车索引是以下路线:
'localhost:3000/partners/cars/'
但我希望有这样的道路:
'localhost:3000/partners/all_cars/'
我怎样才能做到这一点?
我正在尝试编写一个正则表达式来检查文本的第一个字符是否等于@.例如:
@test - 这应该匹配
test @ test - 这应该不匹配
我写了这样的东西:/(@[\w-]+)/i
但是这个正则表达式也是第二个例子匹配,但它不应该......
我有安装路边的问题.当我输入我的控制台时:
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) 我在 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) 在我的模型中,我有以下验证器:
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)
问题是,当用户不接受不显示任何错误的条款时,为什么?
在我的应用程序中,我有两个模型:
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)
现在我想找到所有解决城市字段的地点都有价值:"测试".我怎样才能做到这一点?提前致谢.
我有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方法?
ruby ×4
aasm ×1
activerecord ×1
backbone.js ×1
curb ×1
elixir ×1
hstore ×1
linux ×1
postgresql ×1
regex ×1
routes ×1
rspec ×1
simple-form ×1
sql ×1