Chaining the hell out of ActiveRecord models

So, you want a quick and dirty way to obtain all the models in your Rails app that contain relations targeting a collection (like an has_many relation)?

Dir['app/models/**/*.rb']
  .map {|model| File.basename(model, '.rb')}
  .map(&:camelize)
  .map(&:constantize)
  .select {|section|
    section.reflections.find {|name, reflection|
      reflection.collection?
    }
  }.map(&:to_s)

Demeter law?

You got served

kind of.. ^_^

Returning only an HTTP status code

If your making an API and some methods of your controller doesn’t need to render anything peculiar, you could rely on the head method.

head :ok

For an exhaustive list of the rails mapping you can use the handy cheat gem, created by Josh Susser.

$ gem install cheat
$ cheat status_codes
status_codes:
  Use these codes for the #head or #render methods.  ex:
    head :ok
    render :file => '404.html.erb', :status => :not_found
  
status_codes:
  Use these codes for the #head or #render methods.  ex:
    head :ok
    render :file => '404.html.erb', :status => :not_found
  
  1xx Informational
  
  100 => :continue
  101 => :switching_protocols
  102 => :processing
  
  2xx Success
  
  200 => :ok
...