Skip to content

Instantly share code, notes, and snippets.

@senny
senny / routes.rb
Created January 22, 2013 16:09
:controller option in rails route definitions
MyApp::Application.routes.draw do
# works mostly but has problems with `url_for :controller => 'module/controller'`
resources :posts, :controller => 'Module::Controller'
# works
resources :articles, :controller => 'module/controller'
end
# Hook to save the html page of every failed scenario into the temp
# file directory taht it can be checked after cucumber has finished running.
require 'fileutils'
require 'capybara/util/save_and_open_page'
FAILED_SCENARIO_PAGES_PATH = File.join Rails.root, 'tmp', 'failed_scenarios'
FAILED_SCENARIO_IMAGES_PATH = File.join Rails.root, 'tmp', 'failed_scenarios_images'
FileUtils.rm_rf FAILED_SCENARIO_PAGES_PATH
FileUtils.rm_rf FAILED_SCENARIO_IMAGES_PATH
@senny
senny / respond_with_scaffold.rb
Created February 6, 2013 10:30
Rails 3.2.x scaffolded Controller
class ProductsController < ApplicationController
respond_to :html, :xml
def index
@products = Product.all
respond_with @products
end
def show
@product = Product.find(params[:id])
@senny
senny / gist:4951454
Created February 14, 2013 09:03
CONTROLLER environment variable to filter routes
» rake routes
root GET / pages#home
» export CONTROLLER='non-existing-controller'
» rake routes
» unset CONTROLLER
» rake routes
root GET / pages#home
@senny
senny / output:
Last active December 14, 2015 03:18
rails 3-2-stable remove_column in migrations
THE SCHEMA CHANGES FROM:
ActiveRecord::Schema.define(:version => 0) do
create_table "my_table", :primary_key => "my_table_id", :force => true do |t|
t.integer "col_one"
t.string "col_two", :limit => 128, :null => false
end
end
@senny
senny / 3-2-stable
Created February 27, 2013 19:09
rails debugging: #count with #uniq and #joins
irb(main):001:0> require 'active_record'
:database => ':memory:' )
# Create a database schema to reproduce the bug
ActiveRecord::Schema.define do
create_table :users
create_table :dogs do |t|
t.integer :user_id
-- MySQL dump 10.13 Distrib 5.5.14, for osx10.7 (i386)
--
-- Host: localhost Database: rails-issue-9518_development
-- ------------------------------------------------------
-- Server version 5.5.14
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
require 'active_record'
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :users do |t|
t.timestamps
end
create_table :activities do |t|
t.integer :user_id
def assert_template(options = {}, message = nil)
# Force body to be read in case the template is being streamed.
response.body
case options
when NilClass, Regexp, String, Symbol
options = options.to_s if Symbol === options
rendered = @_templates
msg = message || sprintf("expecting <%s> but rendering with <%s>",
options.inspect, rendered.keys)
@senny
senny / tickets.md
Last active December 15, 2015 02:19
Inflector Tickets for @fxn