내 지역에있는 부동산 관련 정보를 저장하려고합니다.Ruby Data_Mapper 리소스를 저장할 수 없습니다. 다른 데이터 유형이 필요합니다.
저는 Ruby를 Data_Mapper gem과 함께 사용하여 로컬 MySQL 데이터베이스에 데이터를 저장합니다.
모델은 현재 이렇게 같이 :
irb(main):006:0> Suburb.create(:name => "Test", :post_code => 4321)
ArgumentError: arguments may be 1 or 2 Integers, or 1 Range object, was: [:name]
from /var/lib/gems/1.9.1/gems/dm-core-1.2.1/lib/dm-core/collection.rb:390:in `[]'
from /var/lib/gems/1.9.1/gems/dm-core-1.2.1/lib/dm-core/model/property.rb:236:in `name='
from /var/lib/gems/1.9.1/gems/dm-core-1.2.1/lib/dm-core/resource.rb:336:in `block in attributes='
from /var/lib/gems/1.9.1/gems/dm-core-1.2.1/lib/dm-core/resource.rb:332:in `each'
from /var/lib/gems/1.9.1/gems/dm-core-1.2.1/lib/dm-core/resource.rb:332:in `attributes='
from /var/lib/gems/1.9.1/gems/dm-core-1.2.1/lib/dm-core/resource.rb:755:in `initialize'
from /var/lib/gems/1.9.1/gems/dm-validations-1.2.0/lib/dm-validations.rb:129:in `new'
from /var/lib/gems/1.9.1/gems/dm-validations-1.2.0/lib/dm-validations.rb:129:in `create'
from (irb):6
from /usr/bin/irb:12:in `<main>'
: 나는 다음과 같은 오류를 얻을 교외를 만들려고 할 때 나는 그러나, 생성하고 속성 및 상태를 저장할 수있어
class Property
include DataMapper::Resource
property :id, Serial
property :num, String
property :street, String
property :street_type, String
property :price, String
property :block_size, String
property :unimproved_value, String
property :found, DateTime
property :last_seen, DateTime
belongs_to :suburb
end
class Suburb
include DataMapper::Resource
property :id, Serial
property :name, String
property :post_code, Integer
has n, :properties
belongs_to :state
end
class State
include DataMapper::Resource
property :id, Serial
property :name, String
property :abbreviation, String
has n, :suburbs
end
개체를 만들 때 상태를 정의하지 않았기 때문에이 오류가 발생합니까? 속성에 대해 다른 데이터 형식을 시도했지만 여전히 동일한 오류가 발생합니다. 내가 belongs_to와 has_many 관계를 가지고 있기 때문에 내가 이것을 버릴 수있는 유일한 방법이 있을까요?
도움을 주시면 대단히 감사하겠습니다.
새로운 상태를 만들면 다음과 같은 결과가 나옵니다.'=> #' 그러나 Suburb를 만들면 :'= > # ' –
Michael