我有一个多态关联和STI的案例.
# app/models/car.rb
class Car < ActiveRecord::Base
belongs_to :borrowable, :polymorphic => true
end
# app/models/staff.rb
class Staff < ActiveRecord::Base
has_one :car, :as => :borrowable, :dependent => :destroy
end
# app/models/guard.rb
class Guard < Staff
end
Run Code Online (Sandbox Code Playgroud)
为了使多态关联起作用,根据多态关联的API文档,http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#label-Polymorphic+Associations 我必须设置borrowable_type为base_classSTI模型,在我的情况下是Staff.
问题是:如果borrowable_type设置为STI类,为什么它不起作用?
一些测试来证明它:
# now the test speaks only truth
# test/fixtures/cars.yml
one:
name: Enzo
borrowable: staff (Staff)
two:
name: Mustang
borrowable: guard (Guard)
# test/fixtures/staffs.yml
staff:
name: Jullia Gillard
guard:
name: Joni Bravo …Run Code Online (Sandbox Code Playgroud) 我在OS X 10.10上通过CoreOS和Vagrant运行Docker.
当我docker pull ubuntu在CoreOS中运行时,出现以下错误:
$ docker pull ubuntu
Pulling repository ubuntu
cc0067db4f11: Error pulling image (precise) from ubuntu, endpoint: https://cdn-registry-1.docker.io/v1/, Get https://cdn-registry-1.docker.io/v1/images/cc0067db4f11198ef6fd0435f96a973e559b1cebfceb2bc8e4fe527b32045c2f/ancestry: dial tcp: lookup cdn-registry-1.dcc0067db4f11: Error pulling image (precise) from ubuntu, Get https://cdn-registry-1.docker.io/v1/images/cc0067db4f11198ef6fd0435f96a973e559b1cebfceb2bc8e4fe527b32045c2f/ancestry: dial tcp: lookup cdn-registry-1.docker.io on [10.0.2.3]:53: too many redirects
6006e6343fad: Error pulling image (quantal) from ubuntu, endpoint: https://cdn-registry-1.docker.io/v1/, Get https://cdn-registry-1.docker.io/v1/images/6006e6343fadaaeb5dd98436a3cd17eac8c03cabca1ed4c8778d039e72ebcc9c/ancestry: dial tcp: lookup cdn-registry-1.d6006e6343fad: Error pulling image (quantal) from ubuntu, Get https://cdn-registry-1.docker.io/v1/images/6006e6343fadaaeb5dd98436a3cd17eac8c03cabca1ed4c8778d039e72ebcc9c/ancestry: dial tcp: lookup cdn-registry-1.docker.io on [10.0.2.3]:53: too many redirects
7656cbf56a8c: …Run Code Online (Sandbox Code Playgroud) 我想问一下如何为remote选项的AJAX调用添加额外的参数.我有以下简单的形式来搜索资格(它在Coffeescript中):
$('#search_qualification').typeahead
name: 'qualification'
limit: 50
remote:
url: "/search/qualification?term=%QUERY"
Run Code Online (Sandbox Code Playgroud)
我想通过AJAX调用发送另一个参数,也就是说state,通常使用jQuery AJAX调用,我会这样做:
$.ajax
url: "/search/qualification"
dataType: "json"
data:
term: request.term
state: $("#state").val()
Run Code Online (Sandbox Code Playgroud)
我完全无法适应这种类型的typeahead.js,有人可以帮帮我吗?非常感谢
我想问一下为什么在Ruby-1.9.3-p0中有一个splat param1和一个带有默认值赋值的param2,如下所示:
def my_method(*param1, param2 = "default"); end
回报
SyntaxError: (irb):1: syntax error, unexpected '=', expecting ')'
我的解决方法明确地将param1包装在括号中,如下所示:
def my_method((*param1), param2 = "default"); end
非常感谢
是否有一个好的库可以确定PDF页面的维度?
我知道一种方法是使用rghostgem将pdf转换为png然后使用image_sizegem来读取png维度.我不喜欢这种方法.
我很好奇为什么Ruby渲染小数,精度为2不一致.
例如:
helper.number_to_currency 9.995
Run Code Online (Sandbox Code Playgroud)
=>"9.99美元"
同时
helper.number_to_currency 10.995
Run Code Online (Sandbox Code Playgroud)
=>"11.00"......应该是"10.99美元"吗?