Skip to content

Instantly share code, notes, and snippets.

View benmacleod's full-sized avatar

Ben MacLeod benmacleod

  • Melbourne, Australia
View GitHub Profile
# This is what my params looks like
{:group_id=>86,
:payer_id=>1982,
:account_type=>"standard",
:sms_credit_price_ex_tax=>"0.025",
:auto_purchase_sms_credits_amount=>1000,
:setup_invoice=>true,
:locale=>"en-GB",
:timezone=>"London",
describe 'DELETE #destroy' do
let(:dummy) { mock('Dummy') }
it "should find the object with the given ID and destroy it" do
# set the expectations about the interactions
Dummy.should_receive(:find).with(99).and_return dummy
dummy.should_receive(:destroy)
delete :destroy, id: 99
end
end
<%= simple_form_for @item do |i| %>
<%= i.input :name %>
<%= i.input :description %>
<%= i.input :price %>
<%= i.input :zip %>
<%= i.input :weight %>
<%= i.input :volume %>
<%= i.simple_fields_for :item_images do |image| %>
<% image.input :image, as: :file %>
<% end %>
@benmacleod
benmacleod / comment..rb
Last active December 27, 2015 12:49 — forked from workmad3/comment..rb
def self.create_from_parent(parent_type, parent_id, comment_params, current_account)
parent = parent_type.safe_constantize
raise ActiveRecord::RecordNotFound unless parent && (parent.reflect_on_association(:comments).klass == self)
parent.find(parent_id).comments.create(comment_params.merge(account: current_account))
end
@benmacleod
benmacleod / ruby.sh
Last active December 25, 2015 03:29 — forked from anonymous/ruby.sh
sudo apt-get --force-yes install build-essential openssl libreadline6 libreadline6-dev curl \
zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev \
libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison
&&
\curl -L https://get.rvm.io | bash -s stable --autolibs=enabled
&&
@benmacleod
benmacleod / gist:6374314
Last active December 21, 2015 22:19 — forked from radar/gist:6374310
def self.find_by_id_or_first(id)
(id && where(:id => id).first) || first
end
# or...
def self.find_by_id_or_first(id)
order("id = #{id.to_i} DESC").first
end