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
# PROBLEM | |
# | |
# In order to provide agnosticism, a controller generator should know | |
# which methods the ORM make available to find, save, update, etc. | |
# | |
# SOLUTION #1 | |
# | |
# ORM should expose a generator builder that tell us what to do. | |
# This builder exposes AR methods and return custom implementations. | |
# |
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
jose:~/Work/github/rails/railties$[gen*] ruby bin/gen model | |
Usage: | |
bin/gen model NAME [field:type, field:type] [options] | |
Options: | |
-o, [--orm=NAME] # Orm to be invoked | |
# Default: active_record | |
-t, [--test-framework=NAME] # Test framework to be invoked | |
# Default: test_unit |
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
# Configure generators default options. | |
config.generators do |g| | |
g.rails :helper => true, :stylesheets => true | |
g.orm :active_record, :migration => true, :timestamps => true | |
g.template_engine :erb, :layout => true | |
g.test_framework :test_unit, :fixtures => true | |
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 UsersController < ApplicationController | |
respond_to :html, :xml | |
# GET /users | |
# GET /users.xml | |
def index | |
@users = User.all | |
respond_with(@users) | |
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 UsersController < ApplicationController | |
respond_to :html, :xml, :json | |
# GET /users | |
# GET /users.xml | |
def index | |
@users = User.all | |
respond_with(@users) | |
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 ActionController::Presenter | |
attr_reader :controller, :request, :format, :resource, :resource_location | |
def initialize(controller, resource) | |
@controller = controller | |
@request = controller.request | |
@format = controller.formats.first | |
@resource = resource.is_a?(Array) ? resource.last : resource | |
@resource_location = resource |
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 InheritedResources | |
module Userstamp | |
def create_resource(obj) | |
record_user(obj, :creator, :updater) | |
super | |
end | |
def update_resource(obj, *args) | |
record_user(obj, :updater) | |
super |
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
## Optimizing instrumentation | |
# Master | |
overhead index template_1 partial partial_10 coll_10 partial_100 coll_100 uniq_100 | |
129 198 250 224 802 630 6274 4411 4659 | |
overhead index template_1 partial partial_10 coll_10 partial_100 coll_100 uniq_100 | |
128 195 247 222 798 621 6026 4314 4547 |
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
## Problem: change where to redirect on save with success | |
# scaffold respond_with | |
def create | |
@post = Post.new(params[:post]) | |
flash[:notice] = "Post was successfully created" if @post.save | |
respond_with(@post) | |
end | |
# changed respond_with |
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
# Instead of: | |
module MailForm::Callbacks | |
def self.extended(base) | |
base.class_eval do | |
include ActiveSupport::Callbacks | |
define_callbacks :create, :terminator => "result == false", :scope => [:kind, :name] | |
end | |
end | |
def before_create(*args, &block) |