Skip to content

Instantly share code, notes, and snippets.

View dcorking's full-sized avatar

David Corking dcorking

View GitHub Profile
@dcorking
dcorking / rgo.sh
Created November 24, 2012 15:50
Launch some handy cheat sheets and other console windows for Rails development
#!/bin/bash
# Launch some handy cheat sheets and other console windows for Rails development
# in unix-like systems
# http://creativecommons.org/publicdomain/zero/1.0/
# To the extent possible under law, dcorking has waived all copyright
# and related or neighbouring rights to rgo.sh. This work is published
# from: United Kingdom.
@jrochkind
jrochkind / gist:2161449
Created March 22, 2012 18:40
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".

class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
@wdiechmann
wdiechmann / gist:1892556
Created February 23, 2012 12:03
Rendering a string of Erb/HAML back to a string (render :partial from everything else but filesystem)
# My intention is to be able to do this:
#
# from within some view, render a partial
# with the added flavour that the partial is not a file
# but rather a table model instance - like say a Customer,
# a PurchaseOrder, or in this case - a Template
# the partial rendering "should" adhere to all the standard Rails
# magic, ie nested rendering of partials, builders with Erb/HAML,
# I18n translation support to label the most important.
@jcasimir
jcasimir / render_and_redirect.markdown
Created September 11, 2011 21:29
Render and Redirect in Rails 3

Render and Redirect

The normal controller/view flow is to display a view template corresponding to the current controller action, but sometimes we want to change that. We use render in a controller when we want to respond within the current request, and redirect_to when we want to spawn a new request.

Render

The render method is very overloaded in Rails. Most developers encounter it within the view template, using render :partial => 'form' or render @post.comments, but here we'll focus on usage within the controller.

:action

// =========================
// Example 1: using a @mixin
// =========================
// SCSS:
@mixin a_pink_box() {
float: left;
display: block;
color: pink;
@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active August 23, 2025 10:48
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')