This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> Product.best_sellers | |
'SELECT `products`.*, COUNT(*) AS total FROM `products` INNER JOIN order_items ON order_items.product_id = products.id INNER JOIN orders ON orders.id=order_items.order_id WHERE ((orders.payment_state=3) GROUP BY products.id ORDER BY total DESC' | |
# Yay! | |
> @store.products.best_sellers | |
'SELECT `products`.*, COUNT(*) AS total FROM `products` INNER JOIN order_items ON order_items.product_id = products.id INNER JOIN orders ON orders.id=order_items.order_id WHERE (`products`.store_id = 464) AND (orders.payment_state=3) GROUP BY products.id ORDER BY products.name ASC' | |
# Nooo!!! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddSecurityStringToOrder < ActiveRecord::Migration | |
def self.up | |
add_column :orders, :security_string, :string | |
end | |
def self.down | |
remove_column :orders, :security_string | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
undefined |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Colors Git and shows branch | |
function parse_git_branch { | |
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | |
} | |
function proml { | |
local BLUE="\[\033[0;34m\]" | |
local RED="\[\033[0;31m\]" | |
local LIGHT_RED="\[\033[1;31m\]" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1) Point *.example.com in your DNS setup to your server. | |
# | |
# 2) Setup an Apache vhost to catch the star pointer: | |
# | |
# <VirtualHost *:80> | |
# ServerName *.example.com | |
# </VirtualHost> | |
# | |
# 3) Set the current account from the subdomain | |
class ApplicationController < ActionController::Base |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gem install bleak_house | |
Building native extensions. This could take a while... | |
ERROR: Error installing bleak_house: | |
ERROR: Failed to build gem native extension. | |
/usr/bin/ruby extconf.rb install bleak_house | |
extconf.rb:3:in `exec': No such file or directory - ruby-bleak-house build_snapshot.rb (Errno::ENOENT) | |
from extconf.rb:3 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
str = "So don't return this (but do return this)" | |
start = str.index("(")+1 | |
stop = str.rindex(")")-1 | |
str[start..stop] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Tests | |
def test_grouped_options_for_select_with_array | |
assert_dom_equal( | |
"<optgroup label=\"North America\"><option value=\"US\">United States</option>\n<option value=\"Canada\">Canada</option></optgroup><optgroup label=\"Europe\"><option value=\"GB\">Great Britain</option>\n<option value=\"Germany\">Germany</option></optgroup>", | |
grouped_options_for_select([ | |
["North America", | |
[['United States','US'],"Canada"]], | |
["Europe", | |
[["Great Britain","GB"], "Germany"]] | |
]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def optgroups_with_options(groups, options, selected = nil, prompt = nil) | |
return "<option>Error: Sizes don't match.</option>" if groups.size != options.size | |
str = String.new | |
unless prompt.nil? | |
if prompt.is_a? String | |
str += content_tag :option, prompt, :value => "" | |
elsif prompt.is_a? Array | |
str += content_tag( :option, prompt[0], :value => prompt[1]) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="product_row add_new_product" id="new_design"> | |
<a href="#" onclick="try { | |
new Insertion.Before("new_design", "\n<div class=\"product_row add_new_product\" id=\"new_product\">\n <a href=\"#\" onclick=\"try {\nnew Insertion.Before("new_product", "<p>This works.</p>");\n} catch (e) { alert('RJS error:\\n\\n' + e.toString()); alert('new Insertion.Before(\\"new_product\\", \\"<p>This works.</p>\\");'); throw e }; return false;\">Add another product</a></div>"); | |
} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('new Insertion.Before(\"new_design\", \"\\n<div class=\\\"product_row add_new_product\\\" id=\\\"new_product\\\">\\n <a href=\\\"#\\\" onclick=\\\"try {\\nnew Insertion.Before("new_product", "<p>This works.</p>");\\n} catch (e) { alert(\' |