Here is a quick way to test for Rails controller actions. This setup is routed in Rack and makes it easy to confirm your controller actions are available early on in a test. >> CatsController.action(:index).responds_to?(:call) # => true The action() method is available as a class method in ActionController. In Rails 4 action() is available in metal.rb. 228 229 230 231 232 233 234 # rails/actionpack/lib/action_controller/metal.rb # Returns a Rack endpoint for the given action name. def self.action(name, klass = ActionDispatch::Request) do |env| new.dispatch(name, end end :)

You can filter your library requirements depending on the ENV setting. A program can actually use any comparison to filter libraries because the ‘require’ method is only a basic Ruby object.   require ‘some/library’ require ‘another_library’ if ENV[’test’] Another library will only be loaded if ENV[‘test’] is present. Rails autoload and eager_loading take this a bit further. More on that in the future.I wouldn’t create a gem this way, but it’s great to use this functionality for testing or quick programs. :)

I want to create a variety of HTML renderers in my application. In this case I will have many different base templates (ie… gallery view, blog view, and large image view). I start by whipping up an HtmlGallery, which includes method_missing. This is because the renderer should be generic enough to handle any data. 1) Setup the HtmlGallery class   class HtmlGallery def method_missing(name, value=nil) instance_variable_set("@#{name}", value) end   def render <<"END" <div id="gallery-view"> <h2 class="page-title">#{@name}</h2> <ul> #{ @images ? (@images.each { |i| "<li>#{i}</li>" }) : "<li>No Data</li>" } </ul> </div> END end end 2) Run the class on console >> hg = => #<HtmlGallery:0x007fc85c467748>   >> hg.render => "<div id=\"gallery-view\">\n <h2 class=\"page-title\"></h2>\n <ul>\n <li>No Data</li>\n </ul>\n</div>\n" Next I[…]