Skip to content

Instantly share code, notes, and snippets.

View radar's full-sized avatar

Ryan Bigg radar

View GitHub Profile
def pending_orders?
Order.where(:status => Order::PENDING, :user_id => self.id).exists?
end
@radar
radar / fuck.rb
Created February 25, 2012 03:59 — forked from deJaVisions/gist:1906315
class Product < ActiveRecord::Base
has_many :products_materials
has_many :materials, :through => :products_materials
end
class Material < ActiveRecord::Base
has_many :products_materials
has_many :products, :through => :products_materials
end
@radar
radar / filter.rb
Created February 24, 2012 16:27 — forked from anonymous/filter.rb
Make filter DRY
def published_or_authenticated
scope = controller.name.gsub(/Controller$/, '').singularize.constantize.scoped
scope = user_signed_in? ? scope : scope.published
@page = scope.find(params[:id])
end
<!DOCTYPE html>
<html>
<head>
<title>Site</title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= javascript_include_tag "success" %>
<%= csrf_meta_tags %>
</head>
<body class="<%= yield(:class) %>">
# Be sure to restart your server when you modify this file.
#
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters :format => [:json]
end
content_tag :h1 do
[ project.title,
link_to_icon('show', project)
].join(' ')
end
gem 'pg'
@radar
radar / create.rb
Created January 27, 2012 04:18 — forked from anonymous/create.rb
def create
@device = Device.new(params[:device].merge(:user => current_user))
respond_with @device
end
<% if Spree::Config[:address_requires_state] %>
<% have_states = !@order.ship_address.country.states.empty? %>
<%= ship_form.label :state, t(:state) %><span>*</span>
<noscript>
<%= ship_form.text_field :state_name %>
</noscript>
<% state_elements = [
ship_form.collection_select(:state_id, @order.ship_address.country.states,
:id, :name,
{:include_blank => true},
def order_subtotal(order, options={})
options.assert_valid_keys(:format_as_currency, :show_vat_text)
options.reverse_merge! :format_as_currency => true, :show_vat_text => true
amount = order.total
options.delete(:format_as_currency) ? number_to_currency(amount, :format => "<span>%u</span>%n" : amount
end