Skip to content

Instantly share code, notes, and snippets.

View accuser's full-sized avatar

Matthew Gibbons accuser

View GitHub Profile
/ app/views/posts/_form.html.haml
= form_for @post, :url => collection_url do |f|
%fieldset
%legend New Post
%ol
%li= f.text_field :title
%li= f.text_field :tag_list
%fieldset
%ol
%li= f.text_area :body
>> @post = Post.find(BSON::ObjectId("47cc67093475061e3d95369d"))
=> #<Post _id: 47cc67093475061e3d95369d, slug: "life-the-universe-and-everything">
>> post_path(@post)
=> /posts/47cc67093475061e3d95369d
>> post_path(@post, :slug => @post.slug)
=> /posts/47cc67093475061e3d95369d/life-the-universe-and-everything
$ rake routes
posts GET /posts(.:format) {:action=>"index", :controller=>"posts"}
posts POST /posts(.:format) {:action=>"create", :controller=>"posts"}
new_post GET /posts/new(.:format) {:action=>"new", :controller=>"posts"}
edit_post GET /posts/:id(/:slug)/edit(.:format) {:action=>"edit", :controller=>"posts"}
post GET /posts/:id(/:slug)(.:format) {:action=>"show", :controller=>"posts"}
post PUT /posts/:id(/:slug)(.:format) {:action=>"update", :controller=>"posts"}
post DELETE /posts/:id(/:slug)(.:format) {:action=>"destroy", :controller=>"posts"}
# config/routes.rb
Example::Application.routes.draw do
resources :posts, :slug => true
end
# config/initializers/routes_with_slugs.rb
require 'action_dispatch'
module ActionDispatch
module Routing
class Mapper
module Resources
RESOURCE_OPTIONS << :slug
class Resource
/ app/views/layouts/application.html.haml
%html{ :data => { :web_property_id => ENV['GOOGLE_WEB_PROPERTY_ID'] } }
%head
%title My Great Site
= stylesheet_link_tag 'screen.css', :media => 'screen, projection'
= javascript_include_tag :defaults
%body
#content= yield
// public/javascripts/application.js
var _gaq = _gaq || [];
$(document).ready(function() {
var web_property_id = $('html').attr('data-web_property_id');
if ((typeof web_property_id) != 'undefined') {
_gaq.push(['_setAccount', web_property_id]);
_gaq.push(['_trackPageview']);
/ app/views/layouts/application.html.haml
%html{ :data => { :web_property_id => 'UA-XXXXXXX-1' } }
%head
%title My Great Site
= stylesheet_link_tag 'screen.css', :media => 'screen, projection'
= javascript_include_tag :defaults
%body
#content= yield
// public/javascripts/application.js
var _gaq = _gaq || [];
$(document).ready(function() {
_gaq.push(['_setAccount', 'UA-XXXXXXX-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
/ app/views/layouts/application.html.haml
%html
%head
%title My Great Site
= stylesheet_link_tag 'screen.css', :media => 'screen, projection'
= javascript_include_tag :defaults
%body
#content= yield
:javascript
var _gaq = _gaq || [];