Skip to content

Instantly share code, notes, and snippets.

@buoyant
buoyant / regforms_controller.rb
Created December 3, 2012 16:57
controller file of registration form
def dynamic_districts
@districts = District.find_all_by_state_id(params[:id])
respond_to do |format|
format.js
end
end
@buoyant
buoyant / regform.rb
Created December 3, 2012 17:02
model regform.rb
belongs_to :state
belongs_to :district
@buoyant
buoyant / application.js
Created December 3, 2012 17:07
exists in public/javascripts folder
jQuery(document).ready(function() {
jQuery('#regform_state_id').change(function() {
var data=$('#regform_state_id').val();
$.ajax({
type: "POST",
url: "http://"+location.host+"dynamic_districts/"+data,
data: data,
});
});
});
$('#regform_district_id').empty();
<% for district in @districts %>
$('#regform_district_id').append($("<option></option>").attr("value",<%= district.id %>).text('<%= district.name %>'));
<% end %>
post "dynamic_districts/:id" => "regforms#dynamic_districts"
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#regform_district_id').html("<option value=''>Select District</option>");
});
</script>
@buoyant
buoyant / mysql2win
Last active August 29, 2015 14:08
Rails Installer Mysql2 Windows Fix
gem install mysql2 -- '--with-mysql-lib="c:\Program Files (x86)\MySQL\MySQL Server 5.6\lib" --with-mysql-include="c:\Program Files (x86)\MySQL\MySQL Server 5.6\include"'
# for specific version
gem install mysql2 -v=0.3.14 -- '--with-mysql-lib="c:\Program Files (x86)\MySQL\MySQL Server 5.6\lib" --with-mysql-include="c:\Program Files (x86)\MySQL\MySQL Server 5.6\include"'
@buoyant
buoyant / gist:cd7213695ca4d7288e36
Created October 7, 2015 09:43 — forked from Hammadk/gist:0a196dd1ac5ad971df1a
git pre-push hook: get warned before pushing to git master branch
#!/bin/bash
# Warn before pushing to protected branches
# Make script executable with chmod +x pre-push
# Bypass with git push --no-verify
BRANCH=`git rev-parse --abbrev-ref HEAD`
PROTECTED_BRANCHES="^(master|dev|release-*|patch-*)"
if [[ "$BRANCH" =~ $PROTECTED_BRANCHES ]]; then
read -p "Are you sure you want to push to \"$BRANCH\" ? (y/n): " -n 1 -r < /dev/tty
@buoyant
buoyant / deploy.rb
Created October 11, 2015 11:31 — forked from andruby/deploy.rb
Start and Stop tasks for resque workers, with capistrano deploy hook (without God)
after "deploy:symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}"
@buoyant
buoyant / stripe_new_checkout_plugin.rb
Created August 25, 2017 13:37
StripeNewCheckoutPlugin
#-- encoding: UTF-8
module StripeNewCheckoutPlugin
def self.included(base)
base.class_eval do
#
end
end
# credit card commons fields