これが私のコード内の何らかの相互作用なのか、それとも私が使用しているシェープファイル内の命名規則なのかはわかりませんが、次のコードはStack level too deep
メッセージになります
def read_shapefile
@shp_path = Dir[File.join( @tmp_path, '*.shp') ].first
srs_database = RGeo::CoordSys::SRSDatabase::ActiveRecordTable.new
factory = RGeo::Geos.factory(:srs_database => srs_database, :srid => 96805)
#factory = RGeo::Geos::CAPIFactory.new
cartesian_preferred_factory = LandUnit.rgeo_factory_for_column(:location)
RGeo::Shapefile::Reader.open(@shp_path, factory: factory) do |file|
file.each do |record|
cartesian_cast = RGeo::Feature.cast(
record.geometry, factory: cartesian_preferred_factory, project: true)
cartesian_cast.each do |poly|
lu = LandUnit.new
lu.guid = record.attributes[@params['guid']].to_s
lu.country_code = @params['country_code']
lu.location = poly
# error happens here!
lu.save
end
end
end
end
モデルの移行:
class CreateLandUnits < ActiveRecord::Migration
def change
create_table :land_units do |t|
t.string :country_code, null: false, index: true
t.string :guid, index: true
t.geometry :location, srid: 3785
t.timestamps
end
end
end
schema.rb の関連部分:
create_table "land_units", force: true do |t|
t.string "country_code", null: false
t.string "guid"
t.datetime "created_at"
t.datetime "updated_at"
t.spatial "location", limit: {:srid=>3785, :type=>"geometry"}
end
add_index "land_units", ["location"], :name => "index_land_units_on_location", :spatial => true
active_record/transactions.rb
バックトレースは、行 286を指します:
def rollback_active_record_state!
remember_transaction_record_state
yield
rescue Exception
restore_transaction_record_state
raise # HERE<<<
ensure
clear_transaction_record_state
end
すべてを試しました。どんな助けでも大歓迎です。
編集: 誰かがこれらのパラメーターについて疑問に思っている場合に備えて、失敗した呼び出しで、それらは guid: '6020048.00' および country_code: 'ca' に解決されます。
また、ログに次のように表示されることも追加する必要があります。
(0.1ms) BEGIN
SQL (0.6ms) INSERT INTO "land_units" ("country_code", "created_at", "guid", "location", "updated_at")
VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["country_code", "ca"], ["created_at", "2015-03-23 20:59:38.771649"], ["guid", "6020048.00"],
["location", "002000000300000ec90000000100000028c164b311c749d0be4049101977159301c164b311c7508b1140491022249508cfc164b311c7671af24049103f70c23377c164b311c785400940491065d156a4f5c164b311c78493be40491082fd398873c164b311c783e2024049109c841e4650c164b311c78327ba404910ae43343896c164b311c7810e65404910b976a8c3dfc164b311c77c6113404910cf2943e8c7c164b311c777d3ba404910e3e11b1b56c164b311c771ff68404910fdcea7cc13c164b311c7716ef74049110061ae5237c164b311c76d520940491113afcec9eec164b311c7631bad4049114313691234c164b311c75f336f40491154764b6b38c164b311c75249bb40491140bebb55fac164b311c749492e40491135844d8b3fc164b311c740bbbb4049112ae8b30272c164b311c737d9274049111f6444e7acc164b311c72f4d334049111430f7e5f3c164b311c726871640491108fa115ffac164b311c71e34d2404910fe160b0597c164b311c7151806404910f28d86b4f4c164b311c70ca8b0404910e7a793a963c164b311c705b232404910deb9fc574ac164b311c703a91d404910dc20d4806ac164b311c6fb1d64404910d0ed325688c164b311c6f290ef404910c605069167c164b311c6e9e83a404910bacf71a130c164b311c6e0cba9404910af46584a4fc164b311c6f115694049105a80074a79c164b311c6f69ca64049103bc8277f0fc164b311c6facd224049102626e4a97cc164b311c6fec1f340491011192ee217c164b311c703ca8a40490ff67dac4e4ac164b311c707dc6d40490fe171e94d20c164b311c70c6bce40490fc98cc82ecdc164b311c720cc5340490fe45c78305ac164b311c73527f340490ffe8cde5378c164b311c749d0be4049101977159301"], ["updated_at", "2015-03-23 20:59:38.771649"
]]
(0.2ms) ROLLBACK
表示される SQL は、コンソールで問題なく実行されます。それはクレイジービットです。これは、問題が before_save メソッドにあることを示唆していますが、定義していません。