Skip to content

Instantly share code, notes, and snippets.

mkdir -p /usr/local/etc/nginx/sites-{enabled,available}

File locations:

  • nginx.conf to /usr/local/etc/nginx/
  • default and default-ssl to /usr/local/etc/nginx/sites-available
  • homebrew.mxcl.nginx.plist to /Library/LaunchDaemons/

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

@dfang
dfang / gist:d3ecefe66da294340026
Created May 22, 2014 08:27 — forked from dhh/gist:2492118
split a large routes.rb to multiple files
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

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

# Speed things up by not loading Rails env
config.assets.initialize_on_precompile = false
@dfang
dfang / Termfile example
Last active August 29, 2015 14:08
Termfile example
directory = '~/Development/Work/gart360-web'
url = 'http://gart.dev:3000'
before { run "cd #{directory}" }
run 'fs'
tab do
run "tlog"
end
@dfang
dfang / gist:a58bc901c7b584cdbafc
Last active August 29, 2015 14:10
use backup and whenever with capistrano to backup database on vps
1. install bakcup and whenever gem
```
gem 'backup'
gem 'whenever'
```
2. capistrano task(for uploading config file, put it to lib/capistrano/tasks/backup.rake)
```
namespace :backup do
@dfang
dfang / gist:68f5b7667965f54dbe5c
Last active August 29, 2015 14:17
passing arguments to rake/cap task
@dfang
dfang / gist:3168391
Created July 24, 2012 06:33
jquery snippets : to replace console.log
Snippets:
jQuery.logThis = function( text ){
if( (window['console'] !== undefined) ){
console.log( text );
}
}
@dfang
dfang / gist:3168404
Created July 24, 2012 06:36
IRepository<T> Interface
public interface IRepository<T>: IDisposable where T : class
{
/// <summary>
/// Gets all objects from database
/// </summary>
IQueryable<T> All();
/// <summary>
/// Gets objects from database by filter.
/// </summary>