Skip to content

Instantly share code, notes, and snippets.

View workmad3's full-sized avatar

David Workman workmad3

View GitHub Profile
ruby-1.8.7-p248 > module Foo
ruby-1.8.7-p248 ?> def self.included(base)
ruby-1.8.7-p248 ?> def base.do_foo
ruby-1.8.7-p248 ?> define_method :write do
ruby-1.8.7-p248 > puts "1"
ruby-1.8.7-p248 ?> end
ruby-1.8.7-p248 ?> end
ruby-1.8.7-p248 ?> end
ruby-1.8.7-p248 ?> end
=> nil
ruby-1.8.7-p248 > module Foo
ruby-1.8.7-p248 ?> def self.included(base)
ruby-1.8.7-p248 ?> def base.do_foo
ruby-1.8.7-p248 ?> Foo.send :define_method, :write do
ruby-1.8.7-p248 > puts "1"
ruby-1.8.7-p248 ?> end
ruby-1.8.7-p248 ?> end
ruby-1.8.7-p248 ?> end
ruby-1.8.7-p248 ?> end
=> nil
class SubmissionsController < ActionController::Base
scaffold :submission
end
Finally, if the customization at the views level is not enough, you can customize each controller by following these steps:
1) Create your custom controller, for example a Admins::SessionsController:
class Admins::SessionsController < Devise::SessionsController
end
2) Tell the router to use this controller:
devise_for :admins, :controllers => { :sessions = "admin/sessions" }
class A
class << self
private :new
end
end
class String
def xml_to_yaml
Hash.from_xml(self).to_yaml
end
end
a = {:one => {:two => {:three => {:four => "Hello world"}}}}
b = [:one, :two, :three, :four]
b.inject(a) {|h, i| h[i]}
Foo.stub(:new).and_return(@foo = mock(Foo))
@foo.stub!(:bar).and_return("omg!")
class Status < ActiveRecord::Base
ALARM = Status.find_by_name('alarm')
NO_ALARM = Status.find_by_name('no_alarm')
...
end
Status::ALARM
=> <Status:... name="alarm">
map.namespace :aegis do |aegis|
aegis.resources :user_sessions
end