Skip to content

Instantly share code, notes, and snippets.

#The point of this method is to try executing a change on CustomField Kind, i.e. changing from string to text.
#since not all custom fields are interchangeable like this (boolean to integer for example) this validation
#executes he query that updates it, forces a rollback by raising an exception, do nothing if the exception was triggered
#by us(the query ran successfully) and then rescue every other exception and assume it's because of incompoatible types
def validate_value_kind_change
if should_migrate_values?
begin
begin
self.class.transaction do
app.factory('PackageService', function(){
return {
tournamentsToHtml: function(tournaments){
var html = "<table class='table table-tooltip'><tr><td>Tournament</td><td>Markup</td></tr><tbody>"
for (var key in tournaments) {
html += "<tr>" + "<td>" + key + ": " + "</td>" + "<td>" + tournaments[key] + "</td>" + "</tr>"
};
html + "</tbody></table>"
return html
class InvoicePresenter < BasePresenter
def shipping_total(period_start, period_end)
company.invoices.for_period(period_start, period_end ).one_off.sum(:total)
end
end
and then in your view
presenter.shipping_total("11-1-13", "12-1-13")
app.factory( 'AuthService', function($http, $location, $rootScope) {
return {
login: function(email, password) {
currentUser = $http({method: "POST", url: "/login", params: {email: email, password: password}}).
success(function(data, status){
$rootScope.current_user = data.user
return $location.path("/feed");
}).
error(function(data, status){
return $location.path("/login");
@jvans1
jvans1 / gist:5188109
Created March 18, 2013 15:44
Joins with ordering solution
#Issues
# THIS WORKS: search = Company.search(:users_orders_line_items_price_gte => "2", :order => :ascend_by_orders_total )
#since there is an association in the ordering, the scope returned from the first conditions runs through the stack and hits the join class creating the
#necessary join. When this happens it creates a new set of joins values for the scope
# so I can call joins_values on scope, choose the last one and order based on that.(...order("orders.total ASC"))
#This don't: search = Company.search(:users_orders_line_items_price_gte => "2", :order => :ascend_by_identifier )
#Since there is no association in the ordering method, it never runs through the 'joins' class. So when I call joins_values
#on the current scope i get backk {:users => {:orders => :line_items}} since the last value is line_item, i obviously don't
@jvans1
jvans1 / artists.erb
Created October 29, 2012 16:38
artist page view
<!DOCTYPE html>
<html>
<head>
<title>Playlister</title>
</head>
<body>
<h1>Ruby Playlister</h1>
<h2>Artists</h2>
<h3><%=@artist_count%></h3>