Skip to content

Instantly share code, notes, and snippets.

View mrpunkin's full-sized avatar

Bryan Corey mrpunkin

View GitHub Profile
def fetch(col)
t = self.class.arel_table
ar = t.project(t[col]).where(t[:id].eq(id))
self.class.uncached do
self.class.connection.select_value(ar.to_sql)
end
end
render(:template=>'base/header', :formats=>[:mustache], :handlers=>[:erb])
## ActionView::Template::Error (Missing template base/header with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :rabl, :rjs]}
{
"status": <%= response.status %>,
<% if @error %>"error": <%= @error.to_json.html_safe %>,<% end %>
"version": "<%= version(yield) %>",
"template": "<%= controller.controller_name %>-<%= controller.action_name %>",
"result": <%= yield %>
}
## Initial request / response, appcache is outdated so second request won't use cached page but will re-request it.
Processing by Mobile::PhotosController#show as HTML
Parameters: {"id"=>"1052"}
...
Rendered text template within layouts/mobile (0.0ms)
Completed 200 OK in 49ms (Views: 33.0ms | ActiveRecord: 3.1ms | Sphinx: 0.0ms)
object(nil)
node(:total){ @comments.total_entries }
node(:page){ @comments.page }
node(:per_page){ @comments.per_page }
child(@comments => :items) do
extends 'comments/base'
end
TIMESTAMPDIFF(HOUR, '2012-08-30 22:13:31', "2012-12-19 19:04:37") -- Gives me 2660
time_to_sec(timediff("2012-12-19 19:04:37", '2012-08-30 22:13:31'))/3600 -- Gives me 838.9997
@mrpunkin
mrpunkin / gist:4502921
Created January 10, 2013 15:37
Recently moved signup / login to our homepage. Any reason not to do this?
root :to => 'application#index', :as => :home
root :to => 'application#index', :as => :new_user, :via=>:get, :defaults=>{:anchor=>"signup"}
root :to => 'application#index', :as => :login_users, :via=>:get
validate :group_is_real
def group_is_real
errors.add(:group, "must be an already existing group") if group_id and !group
end
class Challenge < ActiveRecord::Base
has_many :challenge_photos, :dependent=>:destroy
has_many :photos, :through=>:challenge_photo
end
SELECT photos.id FROM photos
LEFT OUTER JOIN votes ON votes.photo_id = photos.id
LEFT OUTER JOIN flags ON flags.photo_id = photos.id AND flags.type="Love"
LEFT OUTER JOIN comments ON comments.photo_id = photos.id
WHERE photos.user_id = 38218
GROUP BY photos.id;