0

阶段

在 Rails 3.2 应用程序中,假设我有这个模型:

Point(id:integer, latitude:decimal, longitude:decimal, zoom:integer)

使用脚手架生成器,它会生成一个包含 3 个文本字段的表单,如下所示:

<%= f.text_field :latitude %>
<%= f.text_field :longitude %>
<%= f.text_field :zoom %>

我真的不想拥有这个。我更喜欢使用 Google Maps 地图并将其用于设置表单坐标并进行编辑。

我看到有很多使用Javascript的解决方案,但如果可以避免直接使用JS,它可能是一个不错的选择。

问题

  • 是帮助制作这个的宝石吗?
  • 什么是好的实现?

非常感谢

4

1 回答 1

0

You won't be able to do this without JavaScript.

What you need to do is:

  • Add the google maps map to the page
  • Add a click listener on the map
    • when the user clicks on the map (optionally place a marker and) get the lat/lng coordinates of the event, and use JS (maybe with the help of jQuery) to set your :latitude and :longitude form fields, as well as the current zoom level
于 2012-11-10T14:32:23.570 回答