This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/routes.rb | |
Blah::Application.routes.draw do | |
devise_for :users | |
get "/:username" => "users#show", :as => :user_profile | |
root :to => 'pages#home' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --date=relative --all | grep -Ei 'shit|fuck|damn|\bass\b|asshole' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- see: http://www.w3.org/TR/html5/forms.html#the-label-element --> | |
<!-- stop doing this --> | |
<label for="post_title">Title:</label> <input type="text" id="post_title" name="post[title]"> | |
<!-- start doing this! --> | |
<label>Title: <input type="text" name="post[title]"></label> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ZomgMyThings::Application.routes.draw do | |
devise_for :users | |
scope ":username" do | |
resources :things #=> /some-user-name/things/42 | |
end | |
get "/:username" => "users#show", :as => :user_profile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shared_context 'authenticated user' do | |
before(:each) do | |
@user = Factory(:user) | |
sign_in @user | |
end | |
end | |
require 'spec_helper' | |
describe ThingsController do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ====== A naïve model ======= | |
class User < ActiveRecord::Base | |
has_many :widgets | |
has_many :purchased_widgets, :class_name => 'Widget' | |
end | |
class Widget < ActiveRecord::Base | |
belongs_to :seller, :class_name => 'User', :foreign_key => 'seller_id' | |
belongs_to :buyer, :class_name => 'User', :foreign_key => 'buyer_id' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is pretty typical, and often 'advised' in Rails apps today | |
class ThingController < ApplicationController | |
def create | |
@thing = current_user.things.build(params[:thing]) # YUCK! | |
if @thing.save | |
redirect_to(user_thing_path(@thing.seller, @thing)) | |
else | |
render :new | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Discussion < ActiveRecord::Base | |
belongs_to :thing | |
scope :started_by lambda { |user| where(:initiated_by_id => user) } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Foo | |
end | |
module Foo::Bar | |
end | |
class Baz | |
end | |
class Quux |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<h1>Add a thing to your box</h1> | |
<%= form_for @thing, html: { class: "form-stacked" } do |f| %> | |
<label>Name: <%= f.collection_select :widget_id, @widgets, :id, :name, | |
{include_blank: true}, autofocus: true %></label> | |
<label>Blah: <%= f.text_field :blah %></label> | |
<label>Other stuff: <%= f.text_field :other %></label> | |
<label>Count: <%= text_field_tag :count, @thing_count %></label> |