make_resourceful do
actions :all
before(:create) { current_object.user = current_user }
response_for :index do |format|
format.html
format.pdf do
send_data ContractsDrawer.draw(Contract.find(:all,:order => "start_date")), :filename => "contracts.pdf", :type => "application/pdf", :disposition => "inline"
end
end
before :show do
mtext = "<div style='font-size:11px'><div><b>#{@contract.name}</b></div>"
mtext += "<div>#{@contract.location}</div>"
mtext += "<div>Tel: #{@contract.tel}</div>"
mtext += "<div>Fax: #{@contract.tel}</div></div>"
@map = GMap.new("map_div")
@map.control_init(:large_map => true,:map_type => true)
@map.center_zoom_init([@contract.lat,@contract.lng],12)
@map.overlay_init(GMarker.new([@contract.lat, @contract.lng], :info_window => mtext))
end
before :index do
@map = GMap.new("map_div")
@map.control_init(:large_map => true,:map_type => true)
@map.center_zoom_init([54,-4.1], 5)
markers1 = []
@contracts.each do |contract|
mtext = "<div style='font-size:11px'><div><b>#{contract.trant_ref} #{contract.name}</b></div>"
mtext += "<div>#{contract.location}</div>"
mtext += "<div>Tel: #{contract.tel}</div>"
mtext += "<div>Fax: #{contract.tel}</div></div>"
markers1 << GMarker.new([contract.lat,contract.lng],:info_window => mtext)
end
managed_markers1 = ManagedMarker.new(markers1,0,17)
mm = GMarkerManager.new(@map,:managed_markers => [managed_markers1])
@map.declare_init(mm,'mgr')
end
end
Refactorings
No refactoring yet !
Brianthecoder
March 14, 2008, March 14, 2008 00:00, permalink
make_resourceful do
actions :all
before(:create) { current_object.user = current_user }
response_for :index do |format|
format.html
format.pdf do
send_data ContractsDrawer.draw(Contract.find(:all,:order => "start_date")), :filename => "contracts.pdf", :type => "application/pdf", :disposition => "inline"
end
end
before :show do
map_init
@map.center_zoom_init([@contract.lat,@contract.lng],12)
@map.overlay_init(GMarker.new([@contract.lat, @contract.lng], :info_window => mtext))
end
before :index do
map_init
@map.center_zoom_init([54,-4.1], 5)
managed_markers1 = ManagedMarker.new(markers1,0,17)
mm = GMarkerManager.new(@map,:managed_markers => [managed_markers1])
@map.declare_init(mm,'mgr')
end
end
def map_init
@map = GMap.new("map_div")
@map.control_init(:large_map => true,:map_type => true)
end
mtext = "<div style='font-size:11px'><div><b>#{@contract.name}</b></div>"
mtext += "<div>#{@contract.location}</div>"
mtext += "<div>Tel: #{@contract.tel}</div>"
mtext += "<div>Fax: #{@contract.tel}</div></div>"
markers1 = []
@contracts.each do |contract|
mtext = "<div style='font-size:11px'><div><b>#{contract.trant_ref} #{contract.name}</b></div>"
mtext += "<div>#{contract.location}</div>"
mtext += "<div>Tel: #{contract.tel}</div>"
mtext += "<div>Fax: #{contract.tel}</div></div>"
markers1 << GMarker.new([contract.lat,contract.lng],:info_window => mtext)
end
Hi,
I have this contracts controller with maps. I'm using make_resourefule plugin. Is there any way i can refactor this code for me, please?
Many Thanks,
Rajesh