Skip to content

Instantly share code, notes, and snippets.

View BenMorganIO's full-sized avatar
😀
Why is this here?

Ben A. Morgan BenMorganIO

😀
Why is this here?
View GitHub Profile
@BenMorganIO
BenMorganIO / gist:1218e896bc45cd65feb8
Created May 16, 2014 07:51
Spree install commands
spree install app
Accept all:
spree install app -A
spree install app --auto_accept true
Skip the migrations and seed data:
spree install app --skip-data-install true
Change the version of spree:
require 'benchmark'
n = 100000000
Benchmark.bm do |benchmark|
benchmark.report do
n.times { 2 + 2 } # Fastest Addition
end
benchmark.report do
n.times { 2.+ 2 } # Slowest Addition
@BenMorganIO
BenMorganIO / db-default-users.rb
Last active August 29, 2015 14:03
Spree Admin Rake Task Override
require 'highline/import'
# see last line where we create an admin if there is none, asking for email and password
def prompt_for_admin_password
if ENV['ADMIN_PASSWORD']
password = ENV['ADMIN_PASSWORD'].dup
say "Admin Password #{password}"
else
password = ask('Password [spree123]: ') do |q|
q.echo = false
@BenMorganIO
BenMorganIO / app-controllers-alchemy-admin-base_controller_decorator.rb
Last active August 29, 2015 14:03
Including Spree helpers into AlchemyCMS
Alchemy::Admin::BaseController.class_eval do
include Spree::Core::ControllerHelpers
include Spree::Core::ControllerHelpers::Store
helper Spree::Core::Engine.helpers
# it appears spree is overriding alchemy's layout when the helper methods are included
# in here, we basically "recall" alchemy's original code.
layout :set_layout
private
@BenMorganIO
BenMorganIO / layout in haml
Created July 23, 2014 22:50
Its a layout in haml
%meta{"charset" => "utf-8"}
%title
= title
%meta{"content" => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}
%meta{"content" => "width=device-width, initial-scale=1.0, maximum-scale=1", "name" => "viewport"}
= raw meta_data_tags
= canonical_tag current_store.url
= favicon_link_tag image_path('favicon.ico')
= stylesheet_link_tag 'spree/frontend/all', media: 'screen'
= csrf_meta_tags
@BenMorganIO
BenMorganIO / similar_products.rb
Last active August 29, 2015 14:05
similar products through taxes
Spree::Order.class_eval do
def similiar_products(limit)
# products -> tax_category -> tax_rates -> adjustments -> orders -> products
tax_rates = self.products.map do |product|
product.tax_category.tax_rates
end.flatten
adjustments = tax_rates.map(&:adjustments).flatten
orders = adjustments.map(&:order).compact
@BenMorganIO
BenMorganIO / add_subtitle_to_spree_product.rb
Last active August 29, 2015 14:05
Adding Subtitle to Spree Product Page
# First you need the migration. Run:
#
# $ rails g migration add_subtitle_to_spree_product
#
# And the code is as so:
class AddSubtitleToSpreeProduct < ActiveRecord::Migration
def up
add_column :spree_products, :subtitle, :string
end
@BenMorganIO
BenMorganIO / backtrace.rb
Last active August 29, 2015 14:05
backtrace
13:39:06 web.1 | Started GET "/shop/api/taxons?per_page=50&page=1&q%5Bname_cont%5D=&_=1408394174251" for 127.0.0.1 at 2014-08-18 13:36:36 -0700
13:39:06 web.1 | Processing by Spree::Api::TaxonsController#index as JSON
13:39:06 web.1 | Parameters: {"per_page"=>"50", "page"=>"1", "q"=>{"name_cont"=>""}, "_"=>"1408394174251"}
13:39:06 web.1 | Alchemy::User Load (0.7ms) SELECT "alchemy_users".* FROM "alchemy_users" WHERE "alchemy_users"."spree_api_key" = '' LIMIT 1
13:39:06 web.1 | Rendered /Users/benmorgan/.rvm/gems/ruby-2.1.2/gems/spree_api-2.3.1/app/views/spree/api/errors/must_specify_api_key.v1.rabl (0.6ms)
13:39:06 web.1 | Filter chain halted as :authenticate_user rendered or redirected
13:39:06 web.1 | Completed 401 Unauthorized in 973ms (Views: 963.3ms | ActiveRecord: 0.7ms)
@BenMorganIO
BenMorganIO / fragment_caching.rb
Created August 22, 2014 19:57
Fragment Caching
def key_for(namespace, *objects)
object_collection = []
objects.each do |object|
if object.respond_to? :pluck
object_ids = object.pluck(:id).join '-'
max_updated_at = object.pluck(:updated_at).max.to_s
elsif object.respond_to? :id
object_ids = object.id
max_updated_at = object.respond_to?(:updated) ? object.updated : object.updated_at
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')