ubuntu, ror, jQuery, css, website memo
太嫩, 沒啥心得, 用來紀錄每天學的
2009年3月24日 星期二
YM4R on rails
Rails 當中使用 Google Map:YM4R
rails 2.2.2中ym4r 的bug的修補
google map on Rails
#View
<%= link_to_remote('Update', {:url => { :action => "update"}, :method => :put }) %>
#Controller
# bind the Ruby @map variable to the JS variable map,
# which already exists in the client browser.
# map is by default the name given to a map created from YM4R/GM
# (this could be overriden by passing a second argument to
# the GMap constructor).
#可以從js 拿到變數值 太強啦
@map = Variable.new("map")
# create a marker.
@marker = GMarker.new([24.9,121.6],
:title => "Update",
:info_window => "I have been placed through RJS")
respond_to do |format|
if @location.update_attributes(params[:location])
flash[:notice] = 'Location was successfully updated.'
format.html { redirect_to(@location) }
format.xml { head :ok }
format.js {
render :update do |page|
#clear the map of all overlays.
page << @map.clear_overlays
#Then I add the marker.
page << @map.add_overlay(@marker)
end
}
else
format.html { render :action => "edit" }
format.xml { render :xml => @location.errors, :status => :unprocessable_entity }
end
end
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言