Skip to content

Instantly share code, notes, and snippets.

@jeremygratton
jeremygratton / README.markdown
Created December 6, 2012 02:09 — forked from henrik/README.markdown
This is how we test that all translation keys match up between locales, in Rails.

This is how we test that all translation keys match up between locales.

Stuff that only goes in one locale (such as an admin section) or that can't be translated yet (if you use external translators) can simply go in files that don't match the path "config/locales/??.yml", like "config/locales/wip.fo.yml".

@jeremygratton
jeremygratton / page_specific_js.coffee
Created December 2, 2012 01:35 — forked from kormie/page_specific_js.coffee
My method for page specific JS
window.FooPageJavaScript = class FooPageJavaScript
constructor: ->
@setupPage()
@bindEvents()
@jeremygratton
jeremygratton / rails_admin.sl.yml
Created November 28, 2012 09:55 — forked from petk/rails_admin.sl.yml
Slovenian translation for rails_admin
sl:
admin:
home:
name: "Domov"
pagination:
previous: "« Prejšnja"
next: "Naslednja »"
truncate: "…"
misc:
filter_date_format: "dd.mm.yy" # a combination of 'dd', 'mm' and 'yy' with any delimiter. No other interpolation will be done!
@jeremygratton
jeremygratton / index.md
Created November 27, 2012 00:45 — forked from rstacruz/index.md
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

<!doctype html>
<html>
<head>
<title>Test Template</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.4.2");
google.setOnLoadCallback(function() {
$(".list-item").bind({
keydown: function(e) {
@jeremygratton
jeremygratton / routes.rb
Created November 20, 2012 03:27 — forked from pixeltrix/routes.rb
Examples of advanced Rails 3.0 routes
Rails.application.routes.draw do
get '/(:locale)/products/(:category)/(page/:page).:extension',
:to => 'products#index',
:as => :products,
:constraints => {
:locale => /[a-z]{2}/,
:category => /.+?/,
:page => /\d+/
},
@jeremygratton
jeremygratton / render_and_redirect.markdown
Created November 14, 2012 23:00 — forked from jcasimir/render_and_redirect.markdown
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

$('.submittable').live('change', function() {
$(this).parents('form:first').submit();
});