質問編集履歴
2
質問内容の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -48,4 +48,45 @@
|
|
48
48
|
|
49
49
|
rails (= 4.2.3) was resolved to 4.2.3, which depends on
|
50
50
|
activerecord (= 4.2.3)
|
51
|
-
```
|
51
|
+
```
|
52
|
+
|
53
|
+
### 追記:
|
54
|
+
|
55
|
+
https://github.com/fjl82/activerecord-mysql2spatial-adapter/tree/activerecord-4.2
|
56
|
+
|
57
|
+
4.2 用のブランチがあったので Gemfile で指定してインストールするとインストールできました
|
58
|
+
|
59
|
+
user.rb に
|
60
|
+
```
|
61
|
+
# By default, use the GEOS implementation for spatial columns.
|
62
|
+
self.rgeo_factory_generator = RGeo::Geos.method(:factory)
|
63
|
+
|
64
|
+
# But use a geographic implementation for the :latlon column.
|
65
|
+
set_rgeo_factory_for_column(:user_location_center, RGeo::Geographic.spherical_factory)
|
66
|
+
|
67
|
+
```
|
68
|
+
とかいてみたところエラーが出なかったので使えてるんだと思うのですが使い方がわかりません
|
69
|
+
|
70
|
+
以下のようなマイグレーションで user モデルの location というカラムを point type にしたのですが
|
71
|
+
```
|
72
|
+
create_table :users do |t|
|
73
|
+
t.column :location, :point, null: false
|
74
|
+
```
|
75
|
+
|
76
|
+
user.rb で
|
77
|
+
```
|
78
|
+
before_save :set_columns
|
79
|
+
|
80
|
+
def set_columns
|
81
|
+
self.location = "POINT(137, 39)"
|
82
|
+
puts self.location
|
83
|
+
end
|
84
|
+
```
|
85
|
+
とポイント型のデータを挿入するテストコードをかいてみたのですが
|
86
|
+
puts の結果も SQL のログも値が0になってしまいます
|
87
|
+
```
|
88
|
+
0
|
89
|
+
Mysql2::Error: Cannot get geometry object from data you send to the GEOMETRY field: INSERT INTO `users` (`location`, `created_at`, `updated_at`) VALUES (0, '2019-03-11 04:49:52', '2019-03-11 04:49:52')):
|
90
|
+
```
|
91
|
+
activerecord-mysql2spatial-adapter
|
92
|
+
の使い方がわかる方いらっしゃったら教えていただけないでしょうか
|
1
質問内容の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -25,4 +25,27 @@
|
|
25
25
|
Rails 4.2.3 から MySQL の geometry 型を扱えてる方いましたらジェムを教えていただけないでしょうか
|
26
26
|
|
27
27
|
geometry を使った検索自体は別のフレームワークでやるので
|
28
|
-
Rails からはあるカラムに lat, lng => Point の出し入れができるだけでいいのですが…
|
28
|
+
Rails からはあるカラムに lat, lng => Point の出し入れができるだけでいいのですが…
|
29
|
+
|
30
|
+
|
31
|
+
###追記:
|
32
|
+
|
33
|
+
よく検索にひっかかる armg と activerecord-mysql2spatial-adapter
|
34
|
+
がいずれも Rails 4.2.3 で使えません
|
35
|
+
|
36
|
+
```
|
37
|
+
In Gemfile:
|
38
|
+
armg was resolved to 0.7.1, which depends on
|
39
|
+
activerecord (~> 5)
|
40
|
+
|
41
|
+
rails (= 4.2.3) was resolved to 4.2.3, which depends on
|
42
|
+
activerecord (= 4.2.3)
|
43
|
+
```
|
44
|
+
|
45
|
+
```
|
46
|
+
activerecord-mysql2spatial-adapter was resolved to 0.5.2, which depends on
|
47
|
+
activerecord (< 4.2, >= 4.0)
|
48
|
+
|
49
|
+
rails (= 4.2.3) was resolved to 4.2.3, which depends on
|
50
|
+
activerecord (= 4.2.3)
|
51
|
+
```
|