[LRUG] Proffer and introducing constraints to Rails

James Hunt ohthatjames at gmail.com
Mon Apr 2 01:59:47 PDT 2012


Hello all,

Over the weekend, Paul Mucur (@mudge) and I knocked up a gem called Proffer:
https://github.com/hudge/proffer.

There is more information on GitHub but the summary is that it stops Action
Controller from exposing all defined instance variables to your views by
default
and instead provides a way to explicitly declare your dependencies instead.

For example:

  class PostsController < ApplicationController
    include Proffer

    def new
      proffer :post => Post.new
    end
  end

Our main rationale was to remove some of the global state that seems to
pervade
Rails views. We want to see if forcing you to declare what information you
pass
to a view would make you more mindful of the collaboration between your
objects.
Would we end up with a better design if you couldn't just rely on some
instance
variable being declared further up the chain? In particular, partials that
modify or make decisions based on data set in the controller can be
especially
fiddly to maintain or reuse.

A lot of the talk at last month's TDD fishbowl [1] was about how to make
testing
easier for beginners by improving conventions and we're using the same
principle
here. We're attempting to guide people towards not using global state while
still not imposing a radical change in style. Avdi Grimm's recent "Objects
on
Rails" takes a similar tack with his FigLeaf module [2] which makes it
possible
to mark inherited methods as private as a way of forcing you to consider
your
coupling to APIs that you may be trying to keep isolated.

While there are more drastic attempts at rethinking views such as Erector
[3],
it seems like there might be opportunity for more incremental improvements
to the
standard Rails approach to views.

As a question for the list (besides feedback on the gem which we would
greatly
appreciate), are there any other conventions or constraints we could apply
through software to further explore Rails best practices?

  [1]: http://skillsmatter.com/podcast/agile-testing/lrug-tdd-fishbowl
  [2]: http://objectsonrails.com/#ID-5e701b05-6b1a-4cdf-9e4b-254b8f6c110d
  [3]: http://erector.rubyforge.org/

PS: Remind us to write up how this simple gem led us to contribute to
RubySpec
and stay up until 3 am chasing a bug in RSpec-Rails...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20120402/1e204801/attachment-0003.html>


More information about the Chat mailing list