Skip to content

Instantly share code, notes, and snippets.

# How to re-use the menu partial for a submenu in Refinery CMS >= 0.9.8.5 and < 0.9.9.22
# header menu (main menu) which hides its children.
<%= render :partial => "/shared/menu",
:locals => {
:dom_id => 'menu',
:css => 'menu',
:collection => @menu_pages,
:hide_children => true
} -%>
@kakra
kakra / filter_payment_methods.rb
Created October 14, 2010 22:10
Filter payment methods in Spree depending on the shipping name
# Filter payment methods in Spree depending on the shipping name,
# use the following snippet within your activation method to
# make it work:
#
# CheckoutsController.class_eval { include FilterPaymentMethods }
#
# The magic happens within the InstanceMethods module, change the
# regexp to fit your needs.
#
# Kai Krakow, http://github.com/kakra
@cmaujean
cmaujean / spree-extension-cap-tasks.rb
Created October 17, 2010 00:29
A set of extension management related tasks for using Capistrano on a spreecommerce install. For spree-0-11-stable.
# Spree extension capistrano tasks
# --------------------------------
# by Christopher Maujean
#
# These tasks depend on the existence of the extensions hash.
# The key is name of the directory in vendor/extensions.
# The value is the git url of the extension.
#
# set :extensions, {
# 'my_site' => "git@github.com:/username/spree-my-site.git"
@schof
schof / ability_decorator.rb
Created October 29, 2010 03:15
Add custom cancan abilities on top of Spree
class AbilityDecorator
include CanCan::Ability
def initialize(user)
#############################
can :destroy, LineItem do |item|
item.order.user == user
end
#############################
can :read, Artwork do |artwork|

RailsAdmin and Globalize3

I have a project where I need translated content. Therefore I use globalize3, wich stores its translated attributes in a seperate table that belongs to the original model. And I use RailsAdmin for painless record management.

It took me some time to figure out how to get those working together, but eventually I found a solution that is non invasive and still ok to work with.

The translated model

In my case there is a Snippet class. It holds content for static pages or text passages on the website. There is a good README for globalize3 for installation instructions and documentation.

@kirs
kirs / gist:1180272
Created August 30, 2011 05:51
NginX config for Rails 3.1 & Unicorn
upstream example_backend {
server unix:/var/www/example.com/shared/unicorn.sock;
}
server {
listen 80;
server_name example.com www.example.com;
access_log off;
error_log off;
client_max_body_size 20M;
@jmeirow
jmeirow / dump_models_to_files.rb
Created March 15, 2012 10:12
Dump the data of ActiveRecord::Base based models to .yml files in the Rails db directory.
require 'active_record'
#
# When run from the root directory of a Rails project, this code will dump the data
# of all models inheriting from ActiveRecord. The data is dumped to .yml files in the
# db directory of the Rails app.
#
# This code is not very fast, as it starts up Rake for each model. It could use improvement.
#
# ------ Dependency on ar_fixtures -------
@robdimarco
robdimarco / bootstrap-rvm-and-chef-solo-on-ubuntu.sh
Created March 24, 2012 14:21
Bash script to bootstrap chef solo using RVM on an Ubuntu server
DEFAULT_RUBY_VERSION="1.9.3-p125"
sudo apt-get -y install curl git-core bzip2 build-essential zlib1g-dev libssl-dev autoconf
if [ -x /usr/local/rvm/bin/rvm ]; then
echo "RVM Found..nothing to do";
else
echo "Installing RVM";
curl -o /tmp/rvm-installer -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer
Order.class_eval do
checkout_flow do
go_to_state :address
go_to_state :delivery
go_to_state :payment, :if => lambda { payment_required? }
go_to_state :confirm, :if => lambda { confirmation_required? }
go_to_state :complete
remove_transition :from => :delivery, :to => :confirm
end
end
Spree::Order.class_eval do
silence_warnings do
state_machines.clear
#override state_machine to add choose_reward step
state_machine :initial => 'cart', :use_transactions => false do
event :next do
transition :from => 'cart', :to => 'address'
transition :from => 'address', :to => 'delivery'
transition :from => 'delivery', :to => 'payment', :if => :payment_required?
transition :from => 'delivery', :to => 'complete'