我希望我問這個權利,所以請讓我知道如果我走了。試圖在一個頁面中填充多個json字符串的gmaps4rails
問題是試圖建立從多個控制器繪製一個主頁,顯示從多個控制器最近的位置,即食品,商業等。
眼下單獨列表頁面具有各自的
@json = Controller.all.to_gmaps4rails
繪製地圖我怎麼會做這樣的事情:
@json = Controller1 Controller2 .all.to_gmaps4rails
我希望這個心不是一個noob問題,我只是有不好的一天。多謝你們!
編輯2011年5月12日@seanhill - 這是車型之一,其他部分都非常接近這個格式。首先,我甚至不確定我的主頁是否需要它自己的模型,因爲它根本不與數據庫進行交互,更多的數據從控制器執行工作。感謝Sean的迴應!
class Dining < ActiveRecord::Base
validates_uniqueness_of :name, :message => "already exists"
attr_accessible :name, :address, :cuisine, :latitude, :longitude, :about, :facebook, :twitter, :phone, :website
geocoded_by :address
after_validation :geocode, :if => :address_changed?
acts_as_gmappable :process_geocoding => false
def gmaps4rails_address
"#{self.address}"
end
def gmaps4rails_infowindow
"<h3>#{self.name}</h3><br /><h5>#{self.cuisine}</h5>"
end
def self.search(search)
if search
where('name LIKE ?', "%#{search}%")
else
scoped
end
end
end
你是什麼意思的Controller1 Controller2?你不應該在控制器上調用'.all'。你應該在模型上做到這一點。你能給我們提供一些關於你的模型如何構建的信息嗎? –
肖恩,對不起,我正在尋找從不同的控制器,即信息。商店和餐館,在一個主頁上的1個地圖。下面的答案有效,但我有興趣將信息從控制器移至模型。現在,模型幾乎是腳手架基礎,具有gmappable,_address和_infowindow以及內置於模型中的搜索。 – keade