我的目标是添加圆圈代替标记,以显示工具模型中每个工具的位置的一般区域.我能够根据SO上的其他答案添加圈子,但是使用以下代码我在这个问题的标题中得到错误.
在我的控制器中:
def index
@tools = Tool.all
@json=Tool.all.to_gmaps4rails
@circles = Tool.all{|t| {:longitude => t.longitude, :latitude => t.latitude, :radius =>"1000" }}.to_json
respond_to do |format|
format.html # index.html.erb
format.json { render json: @tools }
end
end
Run Code Online (Sandbox Code Playgroud)
在我的视图文件中:
<%= gmaps({ "markers" => {"data" => @circles}, "circles" => { "data" => @circles} } ) %>
Run Code Online (Sandbox Code Playgroud)
JavaScript错误会将我引导至gmaps4rails.googlemaps.js文件中的第401行:
this.boundsObject.extend(circle.serviceObject.getBounds().getNorthEast());
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
我在将JSON数据发布到我的rails控制器并将我的JSON数据中的字段映射到paremeters上以创建我的实体时遇到了一些问题.
这是动作的样子:
def create
@trip = Trip.new(params[:trip])
if @trip.save
respond_to do |format|
format.json{render :json => @trip, :status => :created, :location => @trip }
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是Web服务器的输出:
Started POST "/trips.json" for 127.0.0.1 at Sat Sep 03 12:37:41 -0400 2011
Processing by TripsController#create as JSON
Parameters: {"title"=>"Charlie"}
AREL (0.5ms) INSERT INTO "trips" ("created_at", "updated_at", "title") VALUES ('2011-09-03 16:37:41.945743', '2011-09-03 16:37:41.945743', NULL)
Completed 201 Created in 15ms (Views: 3.5ms | ActiveRecord: 0.5ms)
Run Code Online (Sandbox Code Playgroud)
正如你可以看到它在标题字段中插入NULL,我希望它能从JSON数据中映射它吗?
这是HTTP请求:
Host localhost:3000
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS …Run Code Online (Sandbox Code Playgroud)