Skip to content

Instantly share code, notes, and snippets.

View manusajith's full-sized avatar

Manu S Ajith manusajith

View GitHub Profile

Subscriptions with stripe

Code examples use the stripe ruby gem. Most of the links are to stripe's documentation.

![stripe's object model][stripe_object_model_diagram]

Initial setup

To start, create some plans.

@manusajith
manusajith / code
Last active August 29, 2015 14:14
class Test
puts "hello"
end
@manusajith
manusajith / routing-error.rb
Last active December 10, 2015 22:08
To catch all routes and get rid of the “No route matches” error, you can add something like the following to config/routes.rb
map.connect '*path', :controller => "pages", :action => "show"
@manusajith
manusajith / RoR-Tips.rb
Last active December 10, 2015 22:08
Ruby and Ruby on Rails Tips for beginers
=begin
Rails' index_by: the easy way to convert an Array to a Hash.
=end
Post.all.index_by(&:title)
=begin
If u r nt sure wat files a Rails generator wud create for u jst add -p for a dry run
=end
rails g model Blog -p
@manusajith
manusajith / try.rb
Last active December 14, 2015 17:59
In Rails, try() lets you call methods on an object without having to worry about the possibility of that object being nil and thus raising an exception
user_details = User.find(id).try(:user_details).try(:first_name)
#no need to worry if user_details is nill
@manusajith
manusajith / import_excel.rb
Last active December 18, 2015 00:58
Import data from excel file
Sample data
|Name | mobile_number |
|Manu | 9447786299 |
|User | 94477xxxxx |
#Step1. install the required spreadsheet gem by entering:
$ sudo gem install spreadsheet
# http://stackoverflow.com/a/8936202
#
# ActiveAdmin already includes the necessary jquery in active_admin/base,
# so just add this to javascripts/active_admin.js after //= require active_admin/base
#
#
# Serialize and Sort
#
# model_name - you guessed it, the name of the model we are calling sort on.
# This is the actual variable name, no need to change it.
@manusajith
manusajith / error_message
Last active December 20, 2015 12:29
received unexpected message :should_recieve with (:update_attributes) -Rspec error for update action
Failure/Error: scheme.should_recieve(:update_attributes).and_return(scheme)
Double "Scheme_1023" received unexpected message :should_recieve with (:update_attributes)
module RSpec
module Mocks
module AnyInstance
class Recorder
def should_recieve(*args)
raise NoMethodError.new "should_recieve: Did you mean 'should_receive' ?"
end
def should_not_recieve(*args)
raise NoMethodError.new "should_not_receive: Did you mean 'should_not_receive' ?"
end
@manusajith
manusajith / 0_reuse_code.js
Created January 16, 2014 09:49
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console