This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RuleBook | |
def RuleBook.add_rules(object, instance_or_class, rules) | |
instance_or_class = instance_or_class.to_s.downcase.strip.to_sym | |
raise(ArgumentError, "'instance_or_class' must equal :instance or :class") unless [:instance, :class].include?(instance_or_class) | |
raise(ArgumentError, "'rules' must be a Hash") unless rules.is_a?(Hash) | |
unless object.instance_variable_get(:@_rulebook_initiated) # Class instance variable. Not class variable. Not instance variable. Is confusing. | |
object.instance_variable_set(:@_rulebook_initiated, true) | |
object.instance_variable_set(:@_rulebook, {:instance=>{}, :class=>{}}) # @_rulebook is actually two rulebooks, instance and class | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
match '/:id', :to => proc { |env| | |
id = env["action_dispatch.request.path_parameters"][:id] | |
model = Slug.find_by_slug(id).model | |
controller = [model.pluralize.camelize,"Controller"].join.constantize | |
controller.action("show").call(env) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rake task to launch multiple Resque workers in development/production with simple management included | |
require 'resque/tasks' # Require Resque tasks | |
namespace :workers do | |
# = $ rake workers:start | |
# | |
# Launch multiple Resque workers with the Rails environment loaded, | |
# so they have access to your models, etc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
respond_to :rss, :only => [:index] | |
def index | |
@deals = Deal.by_city(@city).limit(15) | |
respond_with(@deals) do |format| | |
format.rss { render :rss => @deals, :title => "KupiKon", :item => { :title => :title, :description => :description }} | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveRecord::Base.connection.increment_open_transactions | |
ActiveRecord::Base.connection.begin_db_transaction | |
at_exit do | |
ActiveRecord::Base.connection.rollback_db_transaction | |
ActiveRecord::Base.connection.decrement_open_transactions | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .railsrc for Rails 3, encoding: utf-8 | |
# see http://rbjl.net/49-railsrc-rails-console-snippets | |
if !Rails.application then warn "Rails isn't loaded, yet... skipping .railsrc" else | |
# # # | |
def ripl?; defined?(Ripl) && Ripl.instance_variable_get(:@shell); end | |
# # # | |
# loggers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add this | |
public/javascripts/all.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Based on http://railsapps.github.com/installing-rails-3-1.html | |
cd ~ | |
sudo apt-get -y install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev curl git-core | |
bash < <(curl -sk https://rvm.beginrescueend.com/install/rvm) | |
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
heroku addons:add pgbackups --remote staging | |
heroku addons:add pgbackups --remote production | |
heroku pgbackups:capture --remote production | |
heroku pgbackups:restore DATABASE `heroku pgbackups:url --remote production` --remote staging |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original Source: https://github.com/chneukirchen/styleguide | |
= Christian Neukirchen's Ruby Style Guide | |
You may not like all rules presented here, but they work very well for | |
me and have helped producing high quality code. Everyone is free to | |
code however they want, write and follow their own style guides, but | |
when you contribute to my code, please follow these rules: | |