Skip to content

Instantly share code, notes, and snippets.

@geirarne
Created June 5, 2012 09:04
Show Gist options
  • Save geirarne/2873747 to your computer and use it in GitHub Desktop.
Save geirarne/2873747 to your computer and use it in GitHub Desktop.
Slår meg som noe som burde kunne gjøres på 5 linjer. Men jeg får det ikke til.
class Sculpture < ActiveRecord::Base
# some stuff here
def url
if I18n.locale == I18n.default_locale
'/'+slug
else
'/'+I18n.locale.to_s+'/'+slug
end
end
module Scopes
def published
where("is_published = ? AND published_at < ?", true, Time.now).order('lat DESC')
end
def published_map_markers
m = published.select("lat, lng, city, slug")
array = []
m.each do |marker|
hash = { :lat => marker.lat, :lng => marker.lng, :city => marker.city, :slug => marker.slug, :url => marker.url }
array.push(hash)
end
array
end
end
extend Scopes
end
@geirarne
Copy link
Author

geirarne commented Jun 5, 2012

Problemet er altså published_map_markers, hvor jeg kun skal ha ut fire columns, pluss resultatet fra metoden url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment