Skip to content

Instantly share code, notes, and snippets.

@vijaydev
vijaydev / gist:1472145
Created December 13, 2011 13:35
Rails 3.2.0 Changelogs

The latest release notes is available at http://edgeguides.rubyonrails.org/3_2_release_notes.html

Railties 3.2.0 (unreleased)

  • Speed up development by only reloading classes if dependencies files changed. This can be turned off by setting config.reload_classes_only_on_change to false. José Valim

  • New applications get a flag config.active_record.auto_explain_threshold_in_seconds in the environments configuration files. With a value of 0.5 in development.rb, and commented out in production.rb. No mention in test.rb. fxn

  • Add DebugExceptions middleware which contains features extracted from ShowExceptions middleware José Valim

@vijaydev
vijaydev / Rails
Created November 21, 2010 18:41
Rails
Rails 3 no longer auto loads the lib folder. We can make it auto load the lib folder by putting it in config/application.rb like thus: config.autoload_paths += %W(#{config.root}/lib)
All strings are HTML escaped by default in Rails 3. Need to call html_safe on strings which we know are sure to be safe to display the HTML properly.
Reserved words: "config", "process"
Specifying RailsEnv in Apache configuration (vhost/httpd.conf etc) for Passenger 3.0.0 does not work in Rails 3. Changing that to RakeEnv does the trick. This was fixed in Passenger 3.0.1.
To add the default integer primary key to a table which was created with :id => false setting, we can do add_column :table_name, :id, :primary_key
git remote prune origin - to remove a deleted remote branch.
git rebase -i - interactive rebase with options to pick, squash, discard and reorder commits.
git update-index --assume-unchanged
Undoing a merge:
$ git pull $REMOTE $BRANCH
# uh oh, that wasn't right
$ git reset --hard ORIG_HEAD
# all is right with the world
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@vijaydev
vijaydev / gist:2170020
Created March 23, 2012 11:59 — forked from jrochkind/gist:2161449
A Capistrano Rails Guide

A Capistrano Rails Guide

by Jonathan Rochkind, http://bibwild.wordpress.com

why cap?

Capistrano automates pushing out a new version of your application to a deployment location.

I've been writing and deploying Rails apps for a while, but I avoided using Capistrano until recently. I've got a pretty simple one-host deployment, and even though everyone said Capistrano was great, every time I tried to get started I just got snowed under not being able to figure out exactly what I wanted to do, and figured I wasn't having that much trouble doing it "manually".

require 'benchmark'
def time(times = 1)
unless block_given?
puts "No block provided"
return
end
ret = nil
Benchmark.bm do |x|
x.report { times.times { ret = yield } }
def visit_Arel_Nodes_SelectStatement o
puts caller
[
(visit(o.with) if o.with),
o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join,
("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
(visit(o.limit) if o.limit),
(visit(o.offset) if o.offset),
(visit(o.lock) if o.lock),
].compact.join ' '
imap <silent> <C-K> <% %><Esc>2hi
imap <silent> <C-L> <%= %><Esc>2hi
railsrc_path = File.expand_path('~/.railsrc')
if ( ENV['RAILS_ENV'] || defined? Rails ) && File.exist?( railsrc_path )
begin
load railsrc_path
rescue Exception
warn "Could not load: #{ railsrc_path }" # because of $!.message
end
end
*Gist.vim* Vimscript for creating gists (http://gist.github.com)
Usage |gist-vim-usage|
Tips |gist-vim-tips|
Requirements |gist-vim-requirements|
License |gist-vim-license|
Install |gist-vim-install|
This is a vimscript for creating gists (http://gist.github.com)