12. context "validation" do
let(:post) { Factory.build(:post) }
it "requires a poster" do
post.poster = nil
post.should_not be_valid
post.errors.on(:poster).should be_present
end
end
26. module DecentExposure
def inherited(klass)
closured_exposure = default_exposure
klass.class_eval do
default_exposure(&closured_exposure)
end
super
end
attr_accessor :_default_exposure
def default_exposure(&block)
self._default_exposure = block if block_given?
_default_exposure
end
def expose(name, &block)
closured_exposure = default_exposure
define_method name do
@_resources ||= {}
@_resources[name] ||= if block_given?
instance_eval(&block)
else
instance_exec(name, &closured_exposure)
end
end
helper_method name
hide_action name
end
alias let expose
end
29. def expose(name, &block)
closured_exposure = default_exposure
define_method name do
@_resources ||= {}
@_resources[name] ||= if block_given?
instance_eval(&block)
else
instance_exec(name, &closured_exposure)
end
end
helper_method name
hide_action name
end
alias let expose
46. ActionController::Base.class_eval do
extend DecentExposure
superclass_delegating_accessor :_default_exposure
default_exposure do |name|
model_class = name.to_s.classify.constantize
model_class.find(params["#{name}_id"] || params['id'])
end
end
Version of a longer and likely much more profane talk at the Great Lakes Ruby Bash on April 17th.
Pretty simple but I think it’s a neat approach.
Rails plugin that represents an idiom
Rails plugin that represents an idiom
Rails plugin that represents an idiom
motivations
motivations
how to make that a bit better
inspirations
inspirations
As well as abusing the hell out of resource_controller
can be overridden by default_exposure
Version of a longer and likely much more profane talk at the Great Lakes Ruby Bash on April 17th.
Pretty simple but I think it’s a neat approach.